Jump to content
horst

Imagick Resizer need to be tested (2)

Recommended Posts

Not wanting to change completely the shift of this, but did you have a look at GraphicsMagick? It's a fork of iMagick that seems to have better performance and some large users. Maybe they have better support also. http://www.graphicsmagick.org/

Read about a use case at Etsy here https://codeascraft.com/2010/07/09/batch-processing-millions-of-images/

And the PHP support here http://php.net/manual/en/book.gmagick.php

Why didn't I ever heard of this?  :huh:

Share this post


Link to post
Share on other sites

Why didn't I ever heard of this?  :huh:

Maybe because it isn't widely used in shared host environments. I also only have heard of it here in the forums some time ago. IMagick is the most available image processor (wrapper) after GD-lib. This was the reason to try to make it usable for PW. If people could select / decide which processor gets installed in their hosts, I would be happy to use GraphicksMagick, or one of GraphicksMagick, ImageMagick or NETPBM via the commandline, but this is also not widely usable.

Share this post


Link to post
Share on other sites

If you have never heard of graphics magick than teh reason might be that you have never worked with a serious CMS which has automatic image processing on board like TYPO3. It is actually much more recommended to use Graphics magick rather than Imagemagick as it is processing images much better. If you have TYPO3 installed and you have got on your server ImageMagick and GraphicsMagick avaialable than simply test out the differences. TYPO3 Installtool has a nice Checker about the major imageprocessing tasks needed. By the way TYPO3 is also using GD for some tasks.
Espessially the compression of images is much much better with GraphicsMagick. And smaller images load much better ;-)
TYPO3 is capable to use both ImageMagick OR GraphicsMagick and both together with GD!

I really recommend to setup a testing installation of TYPO3 to test out the differences - you actually only need the Installtool for that! No need to setup the complete INstallation and of course you will need to have both ImageProcessors installed on your server.

sorry it is in German but as you are German you will be able to read it Horst!

https://www.cyon.ch/blog/GraphicsMagick:-Das-bessere-ImageMagick
http://jankohermann.de/typo3-6-2-und-graphicsmagick/

In English
http://wiki.typo3.org/GraphicsMagick

simply install graphicsmagick in the imagemagick compatibility modus and you are all set:

apt-get install graphicsmagick graphicsmagick-imagemagick-compat

in TYPO3 you only need to set GM instead of IM and lots of other settings which are needed for Imaghemagick only - also sRGB needs to be RGB in GraphicsMagick and it will work!

Share this post


Link to post
Share on other sites

Hi Andi,

1) Thanks for the links and for the useful part of the informations.

2) I (personally) allready haveused GraphicsMagick a year ago. In the above post it was said in the past (at least I tried to do so). Besides that: I have used a lot of other image processors in the past 15 years too. But I cannot see any usefullness with installing a software that only integrates image processors. If I want to evaluate the quality of image processors, I use the image processors. ;)

3) GraphicsMagick does a (maybe very) good job, but IMHO it isn't the best tool out there. The best tool in regard of visually quality for photos is NETPBM! - if one know how to use it.

4) And sorry if I have posted in a way that not let you see what I have meant in the first place. What I have tried to do with the imagickresizer, and also have tried to say in the newer posts here, was to bring in a next step of image processing for a wide range of users. It should not only be available for those who are on their own servers. So using apt-get install... isn't an option for all that are not on their own servers.

5) Please do not assume what I have done, nor what I have done not. This is neither purposeful nor pleasing to read. My short and precious free time I like to spend rather different. Maybe with programming something (or doing other) that is useful for PW and a wide range of PW-users.

6) I'm available for paid PW modules development. I allready have built some nice custom ones in regard of image processing. :)

Horst

  • Like 5

Share this post


Link to post
Share on other sites

I have an incoming project that will require automatically adding overlays in multiply mode to images uploaded by the clients. Would you say it'd be easier to use the PHP Gmagick/ImageMagick classes on PW's size() output or go all in into extending the PageImage class? I'm kind of concerned on how to approach caching in this case.. If you have any pointers from your experience, I'm a taker!

Share this post


Link to post
Share on other sites

I definitely go with PWs API first.

I always follow the strategy that the original uploaded image never gets outputed as is.

Therefore I'm able (and it is highly recommended) to upload images with full quality! (Photoshop JPEG: Quality = 12)

You need to keep full quality (PW: quality = 100) for every intermediate step. Only with the last step, that produces an image for output, you need to apply a lower quality setting, e.g. 80.

Example manipulation with watermarking, (using PW API with PageimageManipulator):

// create ImageObject from fullsize WatermarkImage
$wmPng = $pages->get('/mytoolspage/')->watermark;

// create a fullsize image with watermark and quality 80! (the global $config->imageSizerOptions quality is set to 80, so don't need to set it here again individually)
$image->pimLoad('full')->watermarkLogo($wmPng)->pimSave();

// create a medium sized image with watermark and quality 75!
$wmPngMedium = $wmPng->width(960, array('quality'=>100));
$image->width(960, array('quality'=>100))->pimLoad('medium')->watermarkLogo($wmPngMedium)->setQuality(75)->pimSave();

// create a small sized image with watermark and quality 68! Now we first apply the (full) watermark and scale down afterwards:
$image->pimLoad('small')->watermarkLogo($wmPng)->setQuality(100)->pimSave()->width(480, array('quality'=>68));

.

If you want apply those or other manipulations direct on upload, you can go this way:

// is called on hook: addHookBefore 'InputfieldFile::fileAdded'
public function prepareUploadedImage($event) {
    $inputfield = $event->object;
    if ('images' != $inputfield->name) return;     // we assume images field !! name of the field is: images !! otherwise change it

    $p = $inputfield->value['page'];               // get the page
    if ('album' != $p->template) return;           // don't do it on other pages than albums

    $image = $event->argumentsByName("pagefile");  // get the image
    
    // do the image manipulations
    $image->size(900, 600);
    $image->size(600, 400);
    $image->size(300, 200);
    ...
}

If you want to apply the watermarks on uploading, you have to use the identical API calls in the autoload module than you do in the templates:

// is called on hook: addHookBefore 'InputfieldFile::fileAdded'
public function prepareUploadedImage($event) {
    $inputfield = $event->object;
    if ('images' != $inputfield->name) return;     // we assume images field !! name of the field is: images !! otherwise change it

    $p = $inputfield->value['page'];               // get the page
    if ('album' != $p->template) return;           // don't do it on other pages than albums

    $image = $event->argumentsByName("pagefile");  // get the image
    
    // do the image manipulations
    $image->size(900, 600);
    $image->size(600, 400);
    $image->size(300, 200);

    // create ImageObjects from WatermarkImage
    $wmPng = wire('pages')->get('/mytoolspage/')->watermark;
    $wmPngMedium = $wmPng->width(960, array('quality'=>100));
    $wmPngSmall = $wmPng->width(480, array('quality'=>100));
    
    // create variations with watermark
    $image->pimLoad('full')->watermarkLogo($wmPng)->pimSave();
    $image->width(960, array('quality'=>100))->pimLoad('medium')->watermarkLogo($wmPngMedium)->pimSave();
    $image->width(480, array('quality'=>100))->pimLoad('small')->watermarkLogo($wmPngSmall)->pimSave();
}

.

You can also use Pia within those chains if you like to use one of her shortcuts:

$image->contain("square=1200, quality=100")->pimLoad('max1200')->watermarkLogo($wmPng)->setQuality(75)->pimSave();

.

Summary:

  • upload quality = 100%
  • every intermediate quality = 100%
  • final quality = is the only quality lower than 100%

This way you produce very fine images, even with GD-lib. :)

  • Like 7

Share this post


Link to post
Share on other sites

Thanks a lot for your input, I'll find a way to make it happen.

My use case is a bit different though, and GD's limited abilities to composite images with modes will probably exclude it, but you give me a good idea how to tackle the problem! :)

mgTWk8g.png

  • Like 1

Share this post


Link to post
Share on other sites

A quick test shows it works fine for me with GD if I use 24bit PNG with transparency as overlay.

I used this code for the final image:

$img->crop("width=300, height=200, quality=100")->pimLoad('graywm')->setQuality(90)->grayscale()->watermarkLogo($wm, 'c', 0)->save()->url

post-1041-0-13599800-1428769764_thumb.jp

original image cropped via pia

post-1041-0-84163900-1428769776_thumb.jp  +  post-1041-0-64729800-1428769793_thumb.pn  = 

using Pim to grayscale                                                        +   transparent png overlay with colored area

post-1041-0-69941100-1428769821_thumb.jp

the result looks good to me

----

Going one step further and using a pure grayscale overlay (with gray area, not a blue one) enables to change the color on the fly and produce different outputs:

$color1 = array(100, 100, 0);
$wmColor1 = $wm->pimLoad('color1')->setQuality(100)->grayscale()->colorize($color1)->save();
$img->crop("width=300, height=200, quality=100")->pimLoad('color1')->setQuality(90)->grayscale()->watermarkLogo($wmColor1, 'c', 0)->save()->url

post-1041-0-23706900-1428771212_thumb.jp

original

post-1041-0-47274200-1428771250_thumb.jp  +  post-1041-0-45719100-1428771262_thumb.pn

grayscaled using Pim                                                     +  overlay in gray

post-1041-0-72963700-1428771283_thumb.jp

final image with yellow colorized overlay

-------

@Pierre-Luc: maybe there are parts I'm not aware of in your case, but GD isn't that bad in many regards. So, it is very bad in regards of transients and smooth transparencies when it comes to dynamically create and overlay parts.

EDIT: Ah, sorry, I have not looked / read very thoroughly your post. You want use composites with modes post-1041-0-86024400-1428776309.png and that isn't handled at all by GD. It is not a simple overlay with transparency.

  • Like 3

Share this post


Link to post
Share on other sites

Amazing work with this module. Image magik is light years ahead of GD in terms of how will it sizes PNG files. Especially logos where you need to see hard clean lines.  I have noticed that of the 30 logos I have sized with image magik 4 of them came out looking like this.  post-1913-0-24731500-1443565486.png

if I save the file again in photoshop it totally fixes the issue.

might be the images have some kind of bad data that only image magic picks up and GD doesn't?

Or it might be the module...I just wanted to bring it to your attention, just in case it's helpful. 

Here is the original:

post-1913-0-46430200-1443565481_thumb.pn

Again, amazing module!

  • Like 1

Share this post


Link to post
Share on other sites

I'm finding a compatibility issues with CroppableImage and ImagikResizer/PageimageSizerImagick V0.31 plugin. I am wondering if any one else is having issues? 

The Issue:

When both plugins are installed croppableImage stops working properly. It will crop the image but always in the center, and ignores the selection tool that lets specify what part of the image to crop from. 

Versions:

Processwire: 2.6.0

PageimageSizerImagick: 0.31

CroppableImage: 0.84

Note: I wanted to try to put in an issue on the Git page, but it is 404ing right now.

https://github.com/horst-n/PageimageSizerImagick

Share this post


Link to post
Share on other sites

PageimageSizerImagick isn't compatible with PW greater than 2.5.11 !

It doesn't support the then (2.5.11) introduced naming scheme for image variations in PW. It was more like a case study. But maybe you can switch to PW 3 devns, there you will find support for Imagick PHP-Extension, ImageMagick-CLI and NETPBM-CLI supported. :)

If you can do, you need to read upon how to "convert" CroppableImage to work with PW 3. KentBrockman and noodles have posted this into its support thread: https://processwire.com/talk/topic/8709-croppableimage/page-7#entry113941

Edited by horst
  • Like 5

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...