horst

Module
Page Image Manipulator 1

225 posts in this topic

@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

 

1 person likes this

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

 

1 person likes this

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!

1 person likes this

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.

3 people like this

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.

2 people like this

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

2 people like this

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

1 person likes this

Share this post


Link to post
Share on other sites

Sorry, AFAIK, GD doesn't support TIF.

1 person likes this

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 benbyf
      HELLO!
      I've been working on a user messaging module which I am nearly ready to release as version 1.
      Currently I have the below functionality and I'm looking for feedback to what other things may be useful for people looking to add user to user messaging on their sites.
      compose message to one or more users known to PW js to enable tag based UI display of user names input on compose message form display all message threads with reply forms reply to message thread displaying each user name by each message in the thread display "unread" when a thread has new content that hasnt been seen by current user delete or unpublish message thread (configurable) display total message thread count display total unread threads (threads that have new replies that the current user has not seen) delete all message threads and associated data (not meant for the users to have access to) road map
      send email to user on new message to a thread they are included in
    • By louisstephens
      So I was working on a module and trying to include a library (so I could use it across the site) using $modules->get('myModule'); . However, When I go to include the library folder (modeled after the LibFlourish module created some time ago). I keep getting: 
      site/modules/MyModule/libraryName/ProcessWire\filetoinclude.php This comes with an error notifying that "failed to open stream: No such file or directory in ...".. Is ProcessWire supposed to be in the include url, or is there a way around this? Sorry, I am quite new to working with my own modules.
       
      I just noticed the sub forum regarding Development, if someone could move this to the correct area I would appreciate it.
    • By louisstephens
      I wasn't quite sure where to post this, as this is a question regarding the module (sorry if it is in the wrong place). I was wondering if anyone has used the Email to Page module and figured out a way to "move" incoming css to another field, or how to render the css so the message just renders utilizing the css. 
      Right now all of the message contents get dropped into a textarea field and display in a template as a jumbled mess. Perhaps I am missing a formatting option in the text area field to render the css and html.
    • By blynx
      Hej,
      just finished the first working version of my photoswipe bundle. https://github.com/blynx/MarkupProcesswirePhotoswipe
      Haven't published it to the module directory, yet. Wanted to wait for some feedback.
      You can add a photoswipe enabled thumbnail gallery / lightbox to your site like this. Just pass an image field to the renderGallery method:
      <?php $pwpswp = $modules->get('Pwpswp'); echo $pwpswp->renderGallery($page->nicePictures); Options are provided like so:
      <?php $galleryOptions = [ 'imageResizerOptions' => [ 'size' => '500x500' 'quality' => 70, 'upscaling' => false, 'cropping' => false ], 'loresResizerOptions' => [ 'size' => '500x500' 'quality' => 20, 'upscaling' => false, 'cropping' => false ], 'pswpOptions' => (object) [ 'shareEl' => false, 'indexIndicatorSep' => ' von ', 'closeOnScroll' => false ] ]; echo $pswp->renderGallery($page->images, $galleryOptions); More info about all that is in the readme: https://github.com/blynx/MarkupProcesswirePhotoswipe
      It is possible to customize pretty much anything by providing your own templates and scripts.
      What do you think? Any ideas, bugs, critique, requests?
      cheers
      Steffen
    • By kixe
      FieldtypeColor is on github

      Fieldtype stores a 32bit integer value reflecting a RGBA value.
      Input
      4 types of Inputfields provided
      Html5 Inputfield of type='color' (if supported by browser)    Inputfield type='text' expecting a 24bit hexcode string (RGB). Input format: '#4496dd'.
      The background color of the input field shows selected color Inputfield of type='text' expecting 32bit hexcode strings (RGB + alpha channel) Input format: '#fa4496dd' Inputfield with Spectrum Color Picker
      (Options modifiable) Inputfield type='text' with custom JavaScript and/or CSS (since version 1.0.3) Output
      Define output format under 'Details' tab in field settings. Select from the following 8 options
      string 6-digit hex color. Example: '#4496dd' string 8-digit hex color (limited browser support).  Example: '#fa4496dd' string CSS color value RGB. Example: 'rgb(68, 100, 221)' string CSS color value RGB. Example: 'rgba(68, 100, 221, 0.98)' string CSS color value RGB. Example: 'hsl(227, 69.2%, 56.7%)' string CSS color value RGB. Example: 'hsla(227, 69.2%, 56.7%, 0.98)' string 32bit raw hex value. Example: 'fa4496dd' int 32bit. Example: '4198799069' (unformatted storage value) The Fieldtype includes
      Spectrum Color Picker by Brian Grinstead

      SCREENSHOTS
      Input type=text with changing background and font color (for better contrast)

      Input type=color (in Firefox)


      Javascript based input (Spectrum Color Picker)


      Settings Output

       
      Settings Input