horst

Page Image Manipulator 1

Recommended Posts

@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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

@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

 

  • Like 1

Share this post


Link to post
Share on other sites

@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

 

  • Like 1

Share this post


Link to post
Share on other sites
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! :P

1 minute ago, horst said:

Holy ghost, @CaelanStewart, it feeled that you have liked my post just before I had posted it!?! :ph34r::lol::ph34r:

Yes, I'm secretly spying on everything you do! I knew!

  • Like 1

Share this post


Link to post
Share on other sites

@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.

  • Like 3

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

More infos please! which transparent regions? what source format? which outputformat? how do you have defined the background?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

  • Like 2

Share this post


Link to post
Share on other sites

Well that clears that up then, cheers @horst. What does the standard ProcessWire image resizing use as that handles transparency correctly?

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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. :)

  • Like 2

Share this post


Link to post
Share on other sites

@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. ?

  • Like 1

Share this post


Link to post
Share on other sites

Sorry, AFAIK, GD doesn't support TIF.

  • Like 1

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

Ok, no, that wasn't exactly what I suggested. But if this works too, it is a good alternative. :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

@rayorg: currently only the method ->watermarkText() has a param opacity (0-100%). For overlaying images, there isn't a configurable option currently.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By thuijzer
      https://github.com/thuijzer/processwire-FieldtypeBusinessHours
      Fieldtype Business Hours
      ProcessWire Fieldtype for entering business hours (opening hours)
       
      Input format
      Leave a day empty when closed on that day
      Times are in 24 hour format.
      9:00-12:00 9:00-12:00, 13:00-17:30 16:00-2:00  
      Usage in templates
      Days are from 1 to 7 where 1 is Monday and 7 is Sunday (ISO-8601)
      echo $page->field_name->isNowOpen() ? 'Now open' : 'Now closed'; if($page->field_name[1] == null) { echo 'Closed on Monday'; } if($page->field_name[2]->inRange('11:00')) { echo 'Tuesday at 11:00 open'; } echo $page->field_name[1]; echo $page->field_name[1]->entries[0]->getFrom()->format('H:i');  
    • By adrian
           Tracy Debugger for ProcessWire
      The ultimate “swiss army knife” debugging and development tool for the ProcessWire CMF/CMS
       

       
      Integrates and extends Nette's Tracy debugging tool and adds 30+ custom tools designed for effective ProcessWire debugging and lightning fast development
      The most comprehensive set of instructions and examples is available at: https://adrianbj.github.io/TracyDebugger
      Modules Directory: http://modules.processwire.com/modules/tracy-debugger/
      Github: https://github.com/adrianbj/TracyDebugger
      A big thanks to @tpr for introducing me to Tracy and for the idea for this module and for significant feedback, testing, and feature suggestions.
    • By Harmen
      Hello all,
      Was wondering if any of you tried to include the Exact PHP client by Picqer in Processwire (URL)? I am trying to at the moment but I am stuck at the Authorization process. Building it inside a module file to execute a certain function every 6 hours to update something on the website. For the authorization process the file has to execute the following piece of code:
      header('Location:'. $urlThatRedirectsMeToTheLoginOfExact); But each time I am trying  to do so, I get the following error: Cannot modify header information - headers already sent by (output started at /processwire/index.php:55). I am out of options so that's why I am trying to find someone who used this library and could get it to work or someone who knows how I can fix it.
      Tips are highly appreciated (if they work ;))
      Cheers, Harmen
    • By BitPoet
      So I stumbled over the request to allow limiting templates to be used only once under every parent page in this thread
      and found that this would actually come in handy (also in a site I've built).
      The code can be found on github and soon also in the module repo.
      After installation, you'll find a new checkbox "Only once per parent" in the family tab when editing a template.