Jump to content
horst

ImageSizerEngine ImageMagick CLI

Recommended Posts

ImageSizerEngine ImageMagick CLI

Version 0.1.1 beta (requires PW 3.0.10+)


Get it from the modules directory or from github.

For information what it is and how to use and install, please read this Blogpost.


Edited by horst
added link to modules directory
  • Like 7

Share this post


Link to post
Share on other sites

Man, I really wanna try this out on my dev box. You happen to know an easy way of installing imagemagick on windows/xampp?

Share this post


Link to post
Share on other sites

Do you have any (even short) info about the use-cases for those engines? Even a "Just an alternative. Mostly comparable to … in speed/performance/quality" would be helpful for anyone looking at those.

  • Like 1

Share this post


Link to post
Share on other sites

Do you have any (even short) info about the use-cases for those engines? Even a "Just an alternative. Mostly comparable to … in speed/performance/quality" would be helpful for anyone looking at those.

The first thing is, if you do not have the PHP-IMagick Extension available on a server, but are able to use the PHP exec() function for CLI operations. Than this and the NETPBM module are useful.

A quick and short comparision of the current state of all currently available modules is:

The core implemented PHP-Extension Imagick module lacks of support / detection of PNG 8bit transparency files and correct GIF support. Therefor it only processes JPEG and PNG24 images. GIF and PNG8 images are handed over to the GD engine.

If the ImageMagick-CLI can handle PNG8 bit images with transparency is not inspected before image processing. It may or may not, but with a recent, and fully functional ImageMagick installation it should be able to process all sort of image formats and subformats.

The NETPBM-CLI is currently work in progress. With Version 0.1.0, It supports JPEG only. But the other formats will be added as soon as I get time for it. There are no known downsides, I just need time to test and implement this.

The difference in quality is minimal between those three modules. They are all better than the GD lib. To choose one before the other ATM only depends on what is supported on a webserver, or may be on personal preferences.

When the modules are finished, so that they support all kind of formats and subformats, I will publsh a comparision table of the most useful aspects. Until then, it will be helpful if people can test one or more of them and report back how it goes. :)

  • Like 4

Share this post


Link to post
Share on other sites

If anyone interested, I installed Imagick on Win8.1 x64, IIS 8.5, PHP 7.0 x86. I took ImageMagick-6.9.3-6-Q16-x86-dll.exe from http://www.imagemagick.org/script/binary-releases.php#windows (I think the latest version would be ok too). Installed as usual, then I created env variable MAGICK_HOME, pointing to the C:\Program Files (x86)\ImageMagick-6.9.3-Q16\modules\coders. Checked that application is running. Then I downloaded PHP 7.0 Non Thread Safe (NTS) x86 of Imagick from http://pecl.php.net/package/imagick/3.4.0/windows, copied php_imagick.dll to the PHP's extension dir, in my case C:\Program Files (x86)\PHP\v7.0\ext, and added extension=php_imagick.dll to php.ini. Finally I had to restart the computer!

  • Like 3

Share this post


Link to post
Share on other sites

A first comparision in filesize & processing time among the first 4 engines with different qualities. Sharpening is set to soft here. Without sharpening, the Netpbm is much faster, but also more blurry than IMagick without sharpening. In regard of filesize and visual quality, Netpbm is better than IMagick. For the overall usage,   IMagick   as  PHP  extension is best  optimized for speed with a very good  visual quality. It is also faster than the IMagick-CLI engine in most cases.

screen_252.png

screen_253.png

screen_254.png

  • Like 4

Share this post


Link to post
Share on other sites

Here is a better comparision, including all 4 sharpening modes and with 280px images output.
 
I only post the link of an PNG screenshot here, because it is 8MB: http://images.pw.nogajski.de/assets/screen_255.png
 
Here are the values, without the thumbnail images:

screen_256.png

Edited by horst
  • Like 4

Share this post


Link to post
Share on other sites

Hello. This looks good! 1 Problem I had was the fact that using the resize feature (via width(), height(), size()) on large images (started already at 1500xY -.-) would crash PW because of PHP memory issues. I read that PNG8 was still routed to the old GD. Will this be fixed so everything uses Imagick?

I really don't want a server to crash because of those bad memory issues. I prevented it by using following config:

$config->imageSizerOptions = [
    'upscaling' => false,
    'cropping' => false,
    'autoRotation' => true,
    'sharpening' => 'soft',
    'quality' => 85,
    'hidpiQuality' => 55,
    'defaultGamma' => -1,
];

Now after this great announcement of this great module, I commented out this thing and hope that all these memory issue go away.

Share this post


Link to post
Share on other sites

The GD now has complete memory checking before loading images into memory. It has had memory checking since some time already, but I have overseen two points in the code for this, what is now fixed with PW 3.0.10 too.

In regard of the IMagick bug with PNG8 with transparency, we only can and will change this if we are able to detect if IMagick can handle this correct. Otherwise it will be handed over to GD.

  • Like 4

Share this post


Link to post
Share on other sites

Thanks horst for your answer. Does this memory checking prevent this memory error? And if so: how is the UX for this? Do I get a nice red error message or how does this whole memory checking work?

Thanks!

Share this post


Link to post
Share on other sites

Yes, it prevent memory errors. The sizer is invoked in here in Pageimage. If it returns false, for what ever reason, but also for a memorcheck, the error is handled here in Pageimage starting from line 434. It writes a text line into the variation file: "This is intentionally invalid image data.\n"; And it logs that error. But it will not interrupt your page render / page load. It will proceed further content, just the image what would exceed your available memory isn't created, is missing. But this only belongs to the GD-lib, not to IMagick. IMagick can process image manipulation by lines or by chunks, what let it successful work with less memory too.

  • Like 1

Share this post


Link to post
Share on other sites

Our client's hoster (1&1) does not support ImageMagick natively, so I installed your CLI module and pointed to the directory where the executables were uploaded.

I checked with a short PHP script if the executable really are executable and everything worked fine so far.

The module's priority was set to 0.

However, the upload still crashes due to allowed memore issues and the error routes to ImageSizerEngineGD.php :-(

Any suggestions?

Share this post


Link to post
Share on other sites

I assume you are not able to upload and execute binarys on a shared host. I think it isn't allowed / is suppressed by the hoster. At least, that the GD-lib is invoked points to this. You also can force an image engine via API calls:

$image = $image->width(500, array("forceEngine" => "ImageMagickCLI"));

I think you need to ask the hoster where the IMagickCLI resides and take this path.

  • Like 1

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