CaelanStewart Posted November 23, 2016 Share Posted November 23, 2016 @horst, an excellent module for ProcessWire, I'm glad that I now have the opportunity to use it in a practical setting. Though, I have encountered some issues, and though I have found workarounds, I thought I'd still make them known here, in case you did not know. So, I've been creating a system that hooks after the pageSave event, applies a watermark to images in a specific field, and overwrite the original file with it. Along the way, I've noticed the following problems: getPimVariations() does not include any images created and saved with Pim2 unless I reload the page: $pim = $image->pim2Load('watermark'); print $pim->getPimVariations()->count; // prints '0', expected '0' $pim->watermarkLogo($somePageimage, 'center', 5)->pimSave(); print $pim->getPimVariations()->count; // prints '0', expected '1' This also happens: // Call pim on image with existing pim variations $pim = $image->pim2Load(); print $pim->getPimVariations()->count; // prints '1', expected '1' $pim->removePimVariations(); print $pim->getPimVariations()->count; // prints '1', expected '0' I tried to get around the above error by calling pim2Load() on the image again, after calling pimSave(), to see if that'd work, and it caused some kind of infinite loop, or whatever - I had to restart the severs: $pim = $image->pim2Load(); print $pim->getPimVariations()->count; // prints '0', expected '0' $pim->watermarkLogo($watermark, 'center', 5)->pimSave(); $pim = $image->pim2Load(); // Causes max_execution_time timeout print $pim->getPimVariations()->count; // doesn't execute, expected '1' Am I doing something wrong? If I am, I think it may be prudent for you to make clear the limitations of your module. Link to comment Share on other sites More sharing options...
horst Posted November 23, 2016 Author Share Posted November 23, 2016 Hi @CaelanStewart, thanks for trying out and debug the PIM. First thing, - in your code example above, you only have specified the mandatory $prefix in the first call of ->pim2load(). The other calls are completly empty, what may lead to the max_execution_time timeout. Please check, if you really call it without defining a prefix in your code at the webserver, or if you only forgott it in the example above. (?) With the issue you find out about the cached variations array, please try to comment out the line 796 in ImageManipulator02.class.php and see, if this makes a difference, please. Link to comment Share on other sites More sharing options...
CaelanStewart Posted November 24, 2016 Share Posted November 24, 2016 @horst, hi there. I wrote the code I posted specifically for this thread - the prefix is present in the actual code. Perhaps you could add an option to disable the caching of variations, or perhaps add a parameter to the getPimVariations() method that ignores the cache, like so? $pim = $page->image->pim2Load('some-prefix'); $pim->getPimVariations(true); // Passing true skips the cache 1 Link to comment Share on other sites More sharing options...
horst Posted November 24, 2016 Author Share Posted November 24, 2016 @CaelanStewart: I have added it, but changed the default! So, everytime now you get a refreshed version. I think that way round it is more like the common expectations. Only if one have a more advanced usecase, he may be aware of the switch and has a need for it. https://github.com/horst-n/PageImageManipulator/commit/ef8a6af6acc49e31d39fa63d6faa696428e30f83 1 Link to comment Share on other sites More sharing options...
horst Posted November 24, 2016 Author Share Posted November 24, 2016 Holy ghost, @CaelanStewart, it feeled that you have liked my post just before I had posted it!?! 1 Link to comment Share on other sites More sharing options...
CaelanStewart Posted November 24, 2016 Share Posted November 24, 2016 1 minute ago, horst said: @CaelanStewart: I have added it, but changed the default! So, everytime now you get a refreshed version. I think that way round it is more like the common expectations. Only if one have a more advanced usecase, he may be aware of the swotch and has a need for it. https://github.com/horst-n/PageImageManipulator/commit/ef8a6af6acc49e31d39fa63d6faa696428e30f83 Wow, thanks! Good to see active and responsive development! Though, unfortunately, I had avoided the need to get the variations. At least the next guy won't have an issue! 1 minute ago, horst said: Holy ghost, @CaelanStewart, it feeled that you have liked my post just before I had posted it!?! Yes, I'm secretly spying on everything you do! I knew! 1 Link to comment Share on other sites More sharing options...
CaelanStewart Posted November 24, 2016 Share Posted November 24, 2016 @horst, I thought I'd share my implementation of an auto-watermarking module. This module depends on PIM, and also depends on some other stuff specific to the application the module was created for. If anybody wants to use this module for their own uses, you'll have to change the names of fields and templates that you want to apply a watermark to. We (PROGRESS: A Creative Agency) do plan to modify this module for more general use in future, and release it in the module directory. But we are really busy right now, and cannot do so. See the GitHub gist here. 3 Link to comment Share on other sites More sharing options...
cb2004 Posted December 20, 2016 Share Posted December 20, 2016 Nice module, I am using it to add canvas to some images so they are all the same size. On the transparent regions they are being changed to black. Is there any way to stop this other than re-uploading a flattened image? $options = array( 'quality' => 100, 'upscaling' => false, ); $p->image_logo->pim2Load('logo')->setOptions($options)->width(180)->canvas(180, 180)->pimSave()->url Link to comment Share on other sites More sharing options...
horst Posted December 20, 2016 Author Share Posted December 20, 2016 More infos please! which transparent regions? what source format? which outputformat? how do you have defined the background? Link to comment Share on other sites More sharing options...
cb2004 Posted December 20, 2016 Share Posted December 20, 2016 It looks like some PNG files with transparency, the areas which are transparent are changed to black. I will do some more testing when I can. They might be 8 bit PNGs with matte set which could be confusing things. I was just wondering if this was a common occurrence. As it isn't I will dig some more. Link to comment Share on other sites More sharing options...
horst Posted December 21, 2016 Author Share Posted December 21, 2016 Ah, ok, 8bit transparent pngs are not handled correctly by the GD-library! There is no chance. Only solution is to use 24bit PNGs with transparency. 2 Link to comment Share on other sites More sharing options...
cb2004 Posted December 21, 2016 Share Posted December 21, 2016 Well that clears that up then, cheers @horst. What does the standard ProcessWire image resizing use as that handles transparency correctly? Link to comment Share on other sites More sharing options...
horst Posted December 21, 2016 Author Share Posted December 21, 2016 it uses GD-lib by default, but you also can enable the module for IMagick. We inspect the images at first and when using GD-lib, we use different ways for modifying the images. Per default, we want to use all functions that are needed to produce the best possible quality. But for those known image formats, like png8 with transparency, we ommit some steps. (Those that would include GD-lib methods that are known to produce that black background instead keeping the transparency) Link to comment Share on other sites More sharing options...
Mike Rockett Posted December 28, 2016 Share Posted December 28, 2016 I'm busy putting together my blog, and need to crop post feature images. I'm using Twig for my templates, and I have this code at the moment: {# cropping is true by default, centers by default #} {# upscaling is true by default #} {% set image = post.post_image.pim2Load('cropped', true).setOptions({ 'quality': 80, 'sharpening': 'none', }).resize(700,300).smooth().pimSave() %} The resulting image is not cropped to center as I'd expect it to. I could well do this with the built-in tools (as mentioned in your previous post about this), however this results in a severe loss of quality on my end, even if core quality property is set to 100 -- I assume this is a GD issue. Can anything be done to implement auto-cropping? PIM is pretty much the only thing I can find that retains image quality. Thanks! Update: I've decided to go ahead and use AvbImage - always been a fan of Intervention\Image, and it works quite well here. That said, this does still appear to be a bug to me, especially if the croppable property is present. Link to comment Share on other sites More sharing options...
horst Posted December 28, 2016 Author Share Posted December 28, 2016 For simple cropping I use Pia. No need to invoke Pim. Pia has the advantage that she lets you very simple define what you need and she uses all the available ImagerenderingEngines. She isn't bound to GD-lib only, as she only delegates your wishes to the core image engine. 2 Link to comment Share on other sites More sharing options...
Mike Rockett Posted December 29, 2016 Share Posted December 29, 2016 @horst - I knew there was another one, and I have seen this before! Haha! Anyways, I've already implemented AvbImage, and so I'll stick to that for my blog. I'll be sure to give Pia a try on one of my upcoming sites that doesn't need many manipulation features. ? 1 Link to comment Share on other sites More sharing options...
Fantomas Posted February 28, 2017 Share Posted February 28, 2017 Hi @horst, can I use tif-Images as input files? Does it work with GD-lib or do I have to use IM? Link to comment Share on other sites More sharing options...
horst Posted February 28, 2017 Author Share Posted February 28, 2017 Sorry, AFAIK, GD doesn't support TIF. 1 Link to comment Share on other sites More sharing options...
Marc Posted April 7, 2017 Share Posted April 7, 2017 This module is not working for me on PW 3.0.58. I'm trying to convert PNG to JPG. When I do $img->pim2Load('template')->setOptions($options)->width($img->width())->pimSave() I get a fatal error: Quote Exception: Method Pageimage::pim2Load does not exist or is not callable in this context When I use pimLoad instead of pim2Load, there's no error and JPG's are generated. But since I'm on PW 3, I should use pim2Load. I'm calling the function in one of my templates. Any idea as to why pim2Load would not be working? Link to comment Share on other sites More sharing options...
horst Posted April 8, 2017 Author Share Posted April 8, 2017 You need to manually install pim2 under site/modules/, and UN-install pim. Than you can use pim2load. You can read about it in the very first post of this thread: https://processwire.com/talk/topic/4264-page-image-manipulator-1/ right at the top of that post. 1 Link to comment Share on other sites More sharing options...
Marc Posted April 10, 2017 Share Posted April 10, 2017 On 8-4-2017 at 9:49 AM, horst said: You need to manually install pim2 under site/modules/, and UN-install pim. Than you can use pim2load. You can read about it in the very first post of this thread: https://processwire.com/talk/topic/4264-page-image-manipulator-1/ right at the top of that post. I read that post but I was confused by it. But now understand: I need to open the site/modules/PageImageManipulator folder that was downloaded by PW and remove the module files that are not PageImageManipulator02 and then install it. Thanks for the module! Link to comment Share on other sites More sharing options...
horst Posted April 10, 2017 Author Share Posted April 10, 2017 Ok, no, that wasn't exactly what I suggested. But if this works too, it is a good alternative. Link to comment Share on other sites More sharing options...
rayorg Posted April 21, 2017 Share Posted April 21, 2017 This is really great and can't wait to try it out. Is it possible to adjust the watermark transparency, or rather let users adjust the watermark transparency? Reason is, I have found that sometimes, depending on the photo, the watermark can be really hard to see, or too prominent. Being able to adjust the opacity would be great. Thanks, Ray Link to comment Share on other sites More sharing options...
horst Posted April 21, 2017 Author Share Posted April 21, 2017 @rayorg: currently only the method ->watermarkText() has a param opacity (0-100%). For overlaying images, there isn't a configurable option currently. Link to comment Share on other sites More sharing options...
rayorg Posted April 24, 2017 Share Posted April 24, 2017 Ok, thanks for the info. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now