Jump to content
horst

Page Image Manipulator 1

Recommended Posts

Thanks for the info and the module! I will try it out when I have a bit more time. So, you influence filesizes with specifying the quality level (0-100). You can set it sitewide in the config.php (default is 90) or you can pass it individually in an options array everywhere on API level.

Is the last file in your screenshot created via GD, and what setting for quality have you used?

Share this post


Link to post
Share on other sites

Both (with your module and with my module) used default quality option "90" and GD library used. Didn't test "Imagick" Library yet but it must work, if extension is installed.

I checked difference between "Imagick" and "GD" there not much difference about file sizes. Comments about "Imagick" quality is much better for compression than "GD".

  • Like 1

Share this post


Link to post
Share on other sites

A little tip that non-advanced users like me might appreciate:

foreach ($galleryimages as $image) {
  ini_set('max_execution_time', 1200);  // this line resets the timer for max_execution_time with every loop.
  $infoarray = $image->pim2Load('f-')->getImageInfo();
  $thumb = $image->pim2Load('t-')->width(200)->pimSave()->url;
  $full = $image->url;
  if ($infoarray['width'] > 2000) {
    $full = $image->pim2Load('f-')->width(2000)->pimSave()->url;
  }
  echo "<div class='galleryimage'><img class='jslghtbx-thmb' src='$thumb' data-jslghtbx='$full' data-jslghtbx-group='galtsu' data-jslghtbx-caption='$image->description'></img></div>";         
}

That code will skip resizing with PIM, if the original width is not over 2000px.

Share this post


Link to post
Share on other sites

awesome module horst, thank you very much!

think i found a little bug?

// config.php
$config->imageManipulatorOptions = array(
    'outputFormat' => 'png'
);
// template
$image = $image->pim2Load('sticker')->grayscale()->pimSave();

does create a jpg.

$image = $image->pim2Load('sticker')->grayscale()->setOutputFormat('png')->pimSave();

does create a png (that's what i wanted, but setting it in config.php seems not to work)

Share this post


Link to post
Share on other sites

It is not intended to be set as global / default option sitewide. You definitly need to set it with every request. The default behave is, if you do not explicitly define an outputformat, the outputformat is the same as the inputformat:

  • jpg => jpg
  • jpg => setOutputformat('png') => png

So, it is not a bug in the module, but a "bug" in the description here. :)

I will update the description. Thanks for pointing out, @BernhardB.

  • Like 2

Share this post


Link to post
Share on other sites

don't know how hard that would be to implement but in my case it would be better if it was configurable globally. maybe if it is NOT set it will stay "auto" like it is now, but if it is set to eg "png" it will use this as default?

definitely no big issue - just a suggestion for a very very very small improvement ;)

  • Like 1

Share this post


Link to post
Share on other sites

@horst

would it be possible to achieve a stronger blur (like this image on the right: http://codepen.io/tobaco/pen/ZWBRwX)%C2'> effect then the currently available (blur or smooth) with PIM and GD?

i tried various things (playing with transparency and overlaying or multiple blur calls).

the first attempt looks really cheap and the second is to ressource hungry to work for the desired blur effect.

i know that imageMagick can do this, but unfortunately that's no option here. :-/

thanks!

Share this post


Link to post
Share on other sites

@Horst

Thank you for this module. I've hit the anti-aliasing problem in watermarkText() you mentioned back on page 2 of this thread (I'm using PHP7). This fixed the issue for me...

if (function_exists('imageantialias')) { @imageantialias($im1, FALSE); }
  • Like 3

Share this post


Link to post
Share on other sites

Thank you for this module. I've hit the anti-aliasing problem in watermarkText() you mentioned back on page 2 of this thread (I'm using PHP7). This fixed the issue for me...

if (function_exists('imageantialias')) { @imageantialias($im1, FALSE); }

Thank you for the good news! (and the fix) ^-^

  • Like 1

Share this post


Link to post
Share on other sites

Hi,
I don't know if depends of PW devns 3.0.10 or something in my code but this

$watermark = $config->paths->root.$config->site_cdn."wm.png";  
$options = array('outputFormat'=>'jpg','quality'=>70);
// first method
$pic->image->first()->pim2Load('wtm')->setOptions($options)->watermarkLogo($watermark,'SE',8)->pimSave();
// another try
$pixelateVersion = $pic->image->first()->pim2Load('pxtd',true)->setOptions($options)->width(700)->pixelate(30)->pimSave();
$pic->image->add($pixelateVersion);
simply overwrites the first image file without creating a copy with prefix as expected.
I copied this code from another pw installation (2.6)

Share this post


Link to post
Share on other sites

I'm using pim2 as you can see from the code "->pim2Load". In any case (prefix or suffix) the original image has been replaced.
Anything to look in PW, some config options can interferes with the module?

Share this post


Link to post
Share on other sites

I'm using pim2 as you can see from the code "->pim2Load".

Oh, sorry!

--- --- ---

Is $pic->image an imagefield set to hold multiple images or only one image?

Please, can you, for debug purposes, output the filename of the variation, instead of adding it to the imagefield?

$options = array('outputFormat'=>'jpg','quality'=>70);
$originalImage = $pic->image->first();
$pixelateVersion = $originalImage->pim2Load('pxtd',true)->setOptions($options)->width(700)->pixelate(30)->pimSave();
echo "<p>{$originalImage->filename}<br />{$pixelateVersion->filename}</p>";
Edited by horst

Share this post


Link to post
Share on other sites

the image field holds multiple images, that was my first thought :)
the echo outputs the same filename, there is no variation, that's the problem, it replaces the original image 

Share this post


Link to post
Share on other sites

Hhm, for me it is working:

D:/ProcessWire/PW-DEV/pw30/htdocs/site/assets/files/1/nikon2208.jpg
D:/ProcessWire/PW-DEV/pw30/htdocs/site/assets/files/1/nikon2208.-pim2-pxtd.jpg

I used PW 3.0.10

You may look at other modules that work with files and images. Maybe you can create a siteprofile with the exporter or are you able to temporarily disable site-modules in the original site?

So, your code is working, the Pim2 is working, but not in your setup. If possible, I would disable all (autoload and file/image-related) modules, and try if it works then. If yes, enable one module after the other, and check if it is working or if it breaks again.

Or the other way round: disable one module, check if it changes, if not disable the next one, ..., ...

YOu may also first have a look to the Hooks-Section of the Debug Mode Tools in the admin footer to get an overview which modules hook into what, maybe this way you can spot primarily candidates very fast. It all depends on your setup I believe.

  • Like 1

Share this post


Link to post
Share on other sites

Hello, where can I get the PIM2 Module ? currently used with pw. 3.0.23 from the ModulesManager cant find the pim2 Link the one on the first side doesnt work for me. 

And is it on the Memory only ? If i check the variations the is see something like this. 

http://prntscr.com/bmm8aa 

The first two images are generated with the PW Api. 

If its only in the memory it couldnt be used with many of images on one site ? 
 

Tnx  

Share this post


Link to post
Share on other sites

simply go to the modules directory, you find it directly on the first page under "User Favorites", the second item.

Or here.

Your other questions I don't understand. ??

In the modules package are a module pim1 and a module pim2. If you use a PW version greater than 2.5.11, please do not install pim1, install pim2! That's all. Hope this helps?

Share this post


Link to post
Share on other sites

Thaks for your answer I already installed the module from modules manager. Now I also installed the second version. Should i leave the first od better remove ? 

 

Share this post


Link to post
Share on other sites

Yes, please only use the second one. Best is to uninstall the first one. The first one is obsolete, as it only supports the older image variations naming convention, and not the new one, introduced in PW 2.5.11.

  • Like 1

Share this post


Link to post
Share on other sites

Is it possible to invert a PNG with transparency with PIM? I have an image which is essentially a white (255,255,255) shape over a transparent background, and I would like to make the white shape black whilst maintaining the transparent area.

Share this post


Link to post
Share on other sites

I don't know. Have you tried it with negate ? What is the result?

Share this post


Link to post
Share on other sites

Uhm, - doesn't sound good. Transparency has made problems all the last twenty years with GD. I'm not sure, but maybe I have read something about that they have updated their Lib to support it. Maybe the version what is bundled with PHP-7 does support it now (?) <- Not sure on this.

Other than that, I believe we can do nothing. (Using any function would result into the same) :(

 

Share this post


Link to post
Share on other sites

@POWERFULHORSE, if you have Imagick installed on your server you can try a slightly modified version (below) of the function I introduced in this post.

// ImageMagick effects
function imagickal($imagePath, $format, $method, array $arguments) {
    $path_parts = pathinfo($imagePath);
    $dirname = $path_parts['dirname'] . '/';
    $filename = $path_parts['filename'];
    $mod = $method . '-' . implode($arguments, '-');
    $mod = wire('sanitizer')->filename($mod, true);
    $savename = "{$dirname}{$filename}_{$mod}.{$format}";
    if (!file_exists($_SERVER['DOCUMENT_ROOT'] . $savename)) {
        $image = new Imagick($_SERVER['DOCUMENT_ROOT'] . $imagePath);
        call_user_func_array([$image, $method], $arguments);
        $image->setImageFormat($format);
        $image->writeImage($_SERVER['DOCUMENT_ROOT'] . $savename);
    }
    return $savename;
}

I tested it as follows...

$orig = "/site/templates/images/transparent.png";
$after = imagickal($orig, 'png', 'negateImage', [false]);
echo "<img src='$orig'>";
echo "<img src='$after'>";

...and the results...

transparent.pngtransparent_negateImage.png

  • Like 6

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. Field widths entered into the Template Field Widths inputfield are only applied if the Edit Template form is submitted with the Template Field Widths inputfield in an opened state. "Collapsed" is the recommended setting if you think you might also use core inputs for setting field widths in a template context. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/
    • By NehaPillai
      Hello Everyone, I was trying to update SEO meta title, description and meta keywords for my website in Process Wire CMS but it saving in the backend but it is not reflecting on my website, Please help me regarding this error. Please find below attached screen shot for your ref. TIA.


    • 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 35+ 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 adrian
      This module allows you to automatically rename file (including image) uploads according to a configurable format
      This module lets you define as many rules as you need to determine how uploaded files will be named and you can have different rules for different pages, templates, fields, and file extensions, or one rule for all uploads. Renaming works for files uploaded via the admin interface and also via the API, including images added from remote URLs.   Github: https://github.com/adrianbj/CustomUploadNames
      Modules Directory: http://modules.processwire.com/modules/process-custom-upload-names/
      Renaming Rules
      The module config allows you to set an unlimited number of Rename Rules. You can define rules to specific fields, templates, pages, and file extensions. If a rule option is left blank, the rule with be applied to all fields/templates/pages/extensions. Leave Filename Format blank to prevent renaming for a specific field/template/page combo, overriding a more general rule. Rules are processed in order, so put more specific rules before more general ones. You can drag to change the order of rules as needed. The following variables can be used in the filename format: $page, $template, $field, and $file. For some of these (eg. $field->description), if they haven't been filled out and saved prior to uploading the image, renaming won't occur on upload, but will happen on page save (could be an issue if image has already been inserted into RTE/HTML field before page save). Some examples: $page->title mysite-{$template->name}-images $field->label $file->description {$page->name}-{$file->filesize}-kb prefix-[Y-m-d_H-i-s]-suffix (anything inside square brackets is is considered to be a PHP date format for the current date/time) randstring[n] (where n is the number of characters you want in the string) ### (custom number mask, eg. 001 if more than one image with same name on a page. This is an enhanced version of the automatic addition of numbers if required) If 'Rename on Save' is checked files will be renamed again each time a page is saved (admin or front-end via API). WARNING: this setting will break any direct links to the old filename, which is particularly relevant for images inserted into RTE/HTML fields. The Filename Format can be defined using plain text and PW $page variable, for example: mysite-{$page->path} You can preserve the uploaded filename for certain rules. This will allow you to set a general renaming rule for your entire site, but then add a rule for a specific page/template/field that does not rename the uploaded file. Just simply build the rule, but leave the Filename Format field empty. You can specify an optional character limit (to nearest whole word) for the length of the filename - useful if you are using $page->path, $path->name etc and have very long page names - eg. news articles, publication titles etc. NOTE - if you are using ProcessWire's webp features, be sure to use the useSrcExt because if you have jpg and png files on the same page and your rename rules result in the same name, you need to maintain the src extension so they are kept as separate files.
      $config->webpOptions = array(     'useSrcExt' => false, // Use source file extension in webp filename? (file.jpg.webp rather than file.webp) ); Acknowledgments
      The module config settings make use of code from Pete's EmailToPage module and the renaming function is based on this code from Ryan: http://processwire.com/talk/topic/3299-ability-to-define-convention-for-image-and-file-upload-names/?p=32623 (also see this post for his thoughts on file renaming and why it is the lazy way out - worth a read before deciding to use this module). 
       
       
      NOTE:
      This should not be needed on most sites, but I work with lots of sites that host PDFs and photos/vectors that are available for download and I have always renamed the files on upload because clients will often upload files with horrible meaningless filenames like:
      Final ReportV6 web version for John Feb 23.PDF

×
×
  • Create New...