Jump to content

Imagick Resizer need to be tested (2)


horst
 Share

Recommended Posts

No sign of lcms anywhere! According to the docs, it looks like it needs to be included during compile: --with-lcms=yes

My IM installation was manually compiled from source because at the time I set things up, the debian package was out of date and didn't support things I needed.

I can't think of, or find, any way to get delegate info directly using iMagick extension.

Name          Value
-------------------------------------------------------------------------------
CC            gcc -std=gnu99 -std=gnu99
CFLAGS        -fopenmp -g -O2 -Wall -pthread
CONFIGURE     ./configure  '--without-perl' '--with-gslib=yes'
COPYRIGHT     Copyright (C) 1999-2011 ImageMagick Studio LLC
CPPFLAGS      -I/usr/local/include/ImageMagick
CXX           g++
CXXFLAGS      -g -O2 -pthread
DEFS          -DHAVE_CONFIG_H
DELEGATES     bzlib fontconfig freetype gs jpeg jng jp2 png rsvg tiff x11 xml zlib
DISTCHECK_CONFIG_FLAGS --disable-deprecated --with-quantum-depth=16 --with-umem=no --with-autotrace=no --with-fontpath= --with-perl=no
EXEC-PREFIX   /usr/local
FEATURES      OpenMP 
HOST          x86_64-unknown-linux-gnu
LDFLAGS       -L/usr/local/lib 
LIB_VERSION   0x667
LIB_VERSION_NUMBER 6,6,7,5
LIBS          -lMagickCore -ltiff -lfreetype -ljasper -ljpeg -lgs -lpng -lfontconfig -lXext -lSM -lICE -lX11 -lbz2 -pthread -L/usr/local/lib -lrsvg-2 -lgio-2.0 -lgdk_pixbuf-2.0 -lm -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0 -lxml2 -lz -lm -lgomp -lpthread -lltdl
NAME          ImageMagick
PCFLAGS       -fopenmp
PREFIX        /usr/local
QuantumDepth  16
RELEASE_DATE  2011-02-05
VERSION       6.6.7
WEBSITE       http://www.imagemagick.org

Path: [built-in]

Name          Value
-------------------------------------------------------------------------------
NAME          ImageMagick
Path: /usr/local/lib/ImageMagick-6.6.7/config/delegates.xml

Delegate                Command
-------------------------------------------------------------------------------
    blender =>          "blender" -b "%i" -F PNG -o "%o""\n"convert" -concatenate "%o*.png" "%o"
        cdr =>          "uniconvertor" "%i" "%o.svg"; mv "%o.svg" "%o"
        cgm =>          "ralcgm" -d ps -oC < "%i" > "%o" 2> "%Z"
 dng:decode =>          "/usr/bin/ufraw-batch" --silent --wb=camera --black-point=auto --exposure=auto --create-id=also --out-type=png --out-depth=16 "--output=%u.png" "%i"
        dvi =>          "dvips" -q -o "%o" "%i"
        eps<=>pdf       "gs" -q -dQUIET -dSAFER -dBATCH -dUseCIEColor -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 "-sDEVICE=pdfwrite" "-sOutputFile=%o" "-f%i"
        eps<=>ps        "gs" -q -dQUIET -dSAFER -dBATCH -dUseCIEColor -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pswrite" "-sOutputFile=%o" "-f%i"
        fig =>          "fig2dev" -L ps "%i" "%o"
       gplt =>          "echo" "set size 1.25,0.62     set terminal postscript portrait color solid; set output "%o"; load "%i"" > "%u";"gnuplot" "%u"
        hdr =>          "ra_pfm" "%i" "%o"
        hpg =>          "hp2xx" -q -m eps -f `basename "%o"` "%i";     mv -f `basename "%o"` "%o"
       hpgl =>          "if [ -e hp2xx -o -e /usr/bin/hp2xx ]; then     hp2xx -q -m eps -f `basename "%o"` "%i";     mv -f `basename "%o"` "%o";   else     echo "You need to install hp2xx to use HPGL files with ImageMagick.";     exit 1;   fi"
        htm =>          "html2ps" -U -o "%o" "%i"
       html =>          "html2ps" -U -o "%o" "%i"
      https =>          "curl" -s -k -o "%o" "https:%M"
       ilbm =>          "ilbmtoppm" "%i" > "%o"
        man =>          "groff" -man -Tps "%i" > "%o"
       miff<= show      "/usr/local/bin/display" -delay 0 -window-group %[group] -title "%l of %f" "ephemeral:%i"
mpeg:decode =>          "ffmpeg" -v -1 -vframes %S -i "%i" -vcodec pam -an -f rawvideo -y "%u.pam" 2> "%Z"
        pdf<=>eps       "gs" -q -dQUIET -dSAFER -dBATCH -dUseCIEColor -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=epswrite" "-sOutputFile=%o" "-f%i"
        pdf<=>ps        "gs" -q -dQUIET -dSAFER -dBATCH -dUseCIEColor -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pswrite" "-sOutputFile=%o" "-f%i"
        pic =>          "ra_pfm" "%i" "%o"
        png<= launch    "gimp" "%i"
        png<= webp      "cp "%i" "%i.png"; "webpconv" "%i.png"; rm "%i.png"; mv "%i.webp" "%o"
        pnm<= ilbm      "ppmtoilbm" -24if "%i" > "%o"
        pov =>          "povray" "+i%i" -D0 +o"%o" +fn%q +w%w +h%h +a -q9 -kfi"%s" -kff"%n"\n"convert" -concatenate "%o*.png" "%o"
         ps<=>eps       "gs" -q -dQUIET -dSAFER -dBATCH -dUseCIEColor -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=epswrite" "-sOutputFile=%o" "-f%i"
         ps<=>pdf       "gs" -q -dQUIET -dSAFER -dBATCH -dUseCIEColor -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pdfwrite" "-sOutputFile=%o" "-f%i"
         ps<= print     "lpr "%i"
        rad =>          "ra_pfm" "%i" "%o"
       rgba<= rle       "rawtorle" -o "%o" -v "%i"
       scan =>          "scanimage" -d "%i" > "%o"
      scanx =>          "scanimage" > "%o"
      shtml =>          "html2ps" -U -o "%o" "%i"
        sid =>          "mrsidgeodecode" -if sid -i "%i" -of tif -o "%o" > "%u"
        svg =>          "rsvg" "%i" "%o"
        txt<=>ps        "enscript" -o "%o" "%i"
       webp =>          "cp "%i" "%i.webp";"webpconv" -format PNG "%i.webp"; convert "%i.png" "%o";rm "%i.webp" "%i.png"
        wmf =>          "wmf2eps" -o "%o" "%i"
Link to comment
Share on other sites

But now we know why icc conversion is not working on your server.

We can ask the user to run a simple test during module installation that he should answer with yes or no.

Trying to convert a cmyk to sRGB or something. If it looks better after conversion, lcms seems to be available.

  • Like 1
Link to comment
Share on other sites

We need to know the path to convert (or ImageMagick) and on some hosts you can choose from different versions like:

Pfad zu ImageMagick 4.2.9: /usr/bin/ImageMagick_4.2.9/ (für Typo3)
Pfad zu ImageMagick 5.5.4: /usr/bin/
Pfad zu ImageMagick 6.2.6: /usr/bin/ImageMagick_6.2.6/bin/

In this case here, we would test 5.5.4, but Imagick is bound to 6.2.6. Weird, even if we would compare the version from information got through Imagick and the exec call, I don't like to poke around that way.

Showing a cmyk without conversion and showing it after trying to convert. Looks good?  - YES : NO

If 'NO', we can add a short explanation on how to get more information through exec.

Link to comment
Share on other sites

  • 2 weeks later...

Noticed I had to update config.php to:

$config->paths->libs = $_SERVER['DOCUMENT_ROOT'] . '/mysubdirectory/_phpcls/';

to get the install to complete as i did not install into my root www directory - maybe this can be autodetected?

Results of testing locally below:

  ["test"]                                    string(16) "cms-basic_visual"
  ["hasUsedCMS"]                              string(4) "0/18"
  ["executiontime"]                           string(12) "6.2528590000"
  ["engine"]                                  string(18) "Apache 2.0 Handler"
  ["php"]                                     string(6) "5.3.13"
  ["os"]                                      string(83) "Windows NT A-PC 6.0 build 6002 (Windows Vista Business Edition Service Pack 2) i586"
  ["imageMagick"]                             string(5) "6.7.6"
  ["imagick module version"]                  string(5) "3.1.2"
  ["imagick classes"]                         string(56) "Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator"
  ["ImageMagick version"]                     string(34) "ImageMagick 6.7.6-1 2012-03-14 Q16"
  ["ImageMagick copyright"]                   string(46) "Copyright (C) 1999-2012 ImageMagick Studio LLC"
  ["ImageMagick release date"]                string(10) "2012-03-14"
  ["ImageMagick number of supported formats"] string(3) "218"

post-2130-0-36283800-1398712726_thumb.pn

  ["test"]                                    string(19) "cms-with-icc_visual"
  ["hasUsedCMS"]                              string(5) "18/18"
  ["executiontime"]                           string(13) "34.5933610000"
  ["engine"]                                  string(18) "Apache 2.0 Handler"
  ["php"]                                     string(6) "5.3.13"
  ["os"]                                      string(83) "Windows NT A-PC 6.0 build 6002 (Windows Vista Business Edition Service Pack 2) i586"
  ["imageMagick"]                             string(5) "6.7.6"
  ["imagick module version"]                  string(5) "3.1.2"
  ["imagick classes"]                         string(56) "Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator"
  ["ImageMagick version"]                     string(34) "ImageMagick 6.7.6-1 2012-03-14 Q16"
  ["ImageMagick copyright"]                   string(46) "Copyright (C) 1999-2012 ImageMagick Studio LLC"
  ["ImageMagick release date"]                string(10) "2012-03-14"
  ["ImageMagick number of supported formats"] string(3) "218"

post-2130-0-91963000-1398712729_thumb.pn

notice some variation between between results - could someone explain what we are looking for here?

  • Like 1
Link to comment
Share on other sites

We are looking with which Imagick / ImageMagick versions the icc conversion is available. We haven't found any valid answers in the net and also doesn't got one at a imagick forum.

So far we have noticed that the lcms lib needs to be compiled into ImageMagick, but there is no way to check if it is or not via the Imagick-php-extension. (you can read more here in that thread)

If you look at Adrians results, they are both the same, with and without icc conversion. Both doesn't work correct with grayscales and cmyk because tere isn't the lcms extension available. At least we do not need support for cmyk, but for grayscales.

---

EDIT:

The Siteprofile is updated! Have changed the require_once - path issue and embedded the Pageimage Naming Scheme and the latest Dev-branch into it.

(see in the first post)

Edited by horst
Link to comment
Share on other sites

Actually the ImagickResizer seems to work well with:

  • resizing
  • cropping
  • sharpening

but there is an issue I have encountered on two different machines: It is called / processed two times for every image call. I have uploaded the module together with some debugging code to github.

Following are a result without skipping the second process. The images get not cropped well:

post-1041-0-53186600-1399276622_thumb.pn post-1041-0-55179900-1399277146_thumb.jp

With skipping the second call, all works as expected:

post-1041-0-72608000-1399276684_thumb.pn post-1041-0-69550900-1399277176_thumb.jp

But why is it called two times?

We hook into imagesizer::resize before, we set $event->replace to true and set $event->return to the right value (false | true). So why is it like it is?

Edited by horst
Link to comment
Share on other sites

but there is an issue I have encountered on two different machines: It is called / processed two times for every image call. I have uploaded the module together with some debugging code to github.

looks like the imagick resizer module is not set to singleton, and I think it should be:

    public static function getModuleInfo() {
        return array(
            'title' => 'Imagick Resizer',
            'version' => 5,
            'summary' => 'A module for replacing GD resizing with Imagick',
            'href' => 'https://processwire.com/talk/topic/5889-image-quality-problem-on-resize/',
            'singular' => false,
            'autoload' => true
            );
    }

should be

 'singular' => true,
  • Like 5
Link to comment
Share on other sites

few more things i have noticed regarding gamma issues, by playing with the special image  on http://www.4p8.com/eric.brasseur/gamma.html

gamma_dalai_lama_gray.jpg

Even with the correct gamma correction before/after resize, GD2's jpeg encoding at 100% quality is still appalling - mangles images that if saved as pngs are fine. (took me a while to isolate as artifacts can look similar as if the gamma was incorrect).

Using Imagick, I still need to add in the gamma correction similarly to  that in ImageSizer.php. (which i think should be 2.2, not 2.0 as hardcoded).

The default getImageGamma() for a new Imagick object is coming up as 1/2.2 (0.454545), which still needs to be added again via $im->gammaImage() to correctly linearize for resizing. (ie. not do gammaImage(2.2) to push it back to 1 before resizing). Hope this makes sense.

        $this->imageGamma = $this->im->getImageGamma();

            if ($this->imageGamma && $this->imageGamma!=1) {
               $this->im->gammaImage($this->imageGamma);
            }
           
           // resizeImage(), sharpen, etc
           // ......

            if ($this->imageGamma && $this->imageGamma!=1) {
               $this->im->gammaImage(1/$this->imageGamma);
            }

  • Like 1
Link to comment
Share on other sites

Even with the correct gamma correction before/after resize, GD2's jpeg encoding at 100% quality is still appalling - mangles images that if saved as pngs are fine. (took me a while to isolate as artifacts can look similar as if the gamma was incorrect).

Using Imagick, I still need to add in the gamma correction similarly to  that in ImageSizer.php. (which i think should be 2.2, not 2.0 as hardcoded).

The default getImageGamma() for a new Imagick object is coming up as 1/2.2 (0.454545), which still needs to be added again via $im->gammaImage() to correctly linearize for resizing. (ie. not do gammaImage(2.2) to push it back to 1 before resizing). Hope this makes sense.

@robinc: which version of ImagickResizer do you use? Above in a code comment from you I have seen v 0.0.5 which is a very early version.

regarding to gamma correction with GD in imagesizer: Out there in the wild you can find images with gamma 2.2 and gamma 1.8, (mostly), therefor I have set it to 2.0, because there is no way to detect it with GD.

Normally with IMagick using the 16bit colordepth should linearize the gamma setting internally. Manually doing this shouldn't be needed. But I will test this. I have updated my testset and already found some interesting behave. And the gamma test will be the next :)

---

@adrian: I have updated it to version 0.1.5 - And yes, you has set it to singular at the beginning of the project. This was right, but stupid me has changed it. >:(:-[

  • Like 1
Link to comment
Share on other sites

@robinc: which version of ImagickResizer do you use? Above in a code comment from you I have seen v 0.0.5 which is a very early version.

I was using the version included in the v4 download (hence still v0.0.5)

note: the zip still has pwire 4.2.1, so need to upgrade that first before i can use the latest ImagickResizer module.

Any chance you could update the zip to latest? :rolleyes:

Link to comment
Share on other sites

Actually the ImagickResizer seems to work well with:

  • resizing
  • cropping
  • sharpening

but there is an issue I have encountered on two different machines: It is called / processed two times for every image call. I have uploaded the module together with some debugging code to github.

Following are a result without skipping the second process. The images get not cropped well:

attachicon.gifpw_imagickresizer_processing_2times_01.png attachicon.gifpw_imagickresizer_processing_2times_badimage.jpg

With skipping the second call, all works as expected:

attachicon.gifpw_imagickresizer_processing_2times_02.png attachicon.gifpw_imagickresizer_processing_2times_goodimage.jpg

But why is it called two times?

We hook into imagesizer::resize before, we set $event->replace to true and set $event->return to the right value (false | true). So why is it like it is?

InputfieldImage does this:

 

L#68

if($this->maxWidth && $pagefile->width > $this->maxWidth) {
    $pagefile2 = $pagefile->width($this->maxWidth);
    unlink($pagefile->filename);
    rename($pagefile2->filename, $pagefile->filename);
    $pagefile->getImageInfo(true); // force it to reload it's dimensions
}

if($this->maxHeight && $pagefile->height > $this->maxHeight) {
    $pagefile2 = $pagefile->height($this->maxHeight);
    unlink($pagefile->filename);
    rename($pagefile2->filename, $pagefile->filename);
    $pagefile->getImageInfo(true);
}

That's two resizes for me. While questioning if it shouldn't do only 1 resize.

  • Like 2
Link to comment
Share on other sites

@soma: it is right that this should be called only once, regardless if it need to correct one or both dimensions. I have send a pull request for it.

But I think this has nothing to do with the issues I have encountered that the ImagickResizer is called two times, because I have not had set any max-dimensions and also fileAdded isn't invoked when calling size, width, height on pageimages. It is invoked by file adding / uploading, as you have to deal with with your fantastic Images Manager. (yep, have read about the break with the newest dev branch)

Link to comment
Share on other sites

@horst, I just stumbled over this and thought of this thread :) I see that it may not the real issue here. Are you saying you get this problem with ImagesManager? I just committed suizi.. er an update to ImagesManager to account for various issues I encountered with new PW. Also there was a fileAdded triggered two times before that was due to some strange things with getting to work max image dimension to work, since it's something that only the InputfieldImage is dealing with.

Link to comment
Share on other sites

@robinc: I have added the code with get and set gamma to the module. But it doesn't work every time. :(

I have had it in the code before and than have removed it again, because it seems not to work consistent over different IM-versions and I have read that going into 16bit depth mode will do that internally.

But now with coming to test it, I must see it doesn't do it as promised. :(

So, on my local machine (ImageMagick 6.8.8-4 Q16) applying gamma correction works as expected, but on a live account (ImageMagick 6.6.9-7 Q16) it do not!

post-1041-0-42750700-1399364238_thumb.pn

I have played around with the point where to call it, but nothing changes. We need to do more testing, - if it gets a value from the image or not and that like.

---

In a post above you have said that you are interested in interpolation methods for upscaling, so if I personally would try to avoid this, it sounds interesting for others. If you like, we can put a check into the code just before it comes to resizing. When it detects that it should and is allowed to upscale, we can use other methods for it. Can you provide some lines to this. :)

PS: If I find the time I will update the site profile this evening.

---

EDIT: I have found out that on my online account (ImageMagick 6.6.9-7 Q16) the function getImageGamma() returns 0 for all images. Don't know why, but have changed the code to asume a Gamma of 2.2 in those cases. We have to observe these further.

Edited by horst
Link to comment
Share on other sites

@horst, I just stumbled over this and thought of this thread :) I see that it may not the real issue here. Are you saying you get this problem with ImagesManager? I just committed suizi.. er an update to ImagesManager to account for various issues I encountered with new PW. Also there was a fileAdded triggered two times before that was due to some strange things with getting to work max image dimension to work, since it's something that only the InputfieldImage is dealing with.

No, I'm currently not using Images Manager with this. I'm working with the pure basics (ImagesSizer, ImagickResizer, Pageimage, PageimageNamingScheme) :) and try to test against all issues that was reported in the past I can remember. And if it isn't allready fixed, provide a fix or report it to Ryan.

Link to comment
Share on other sites

Uploaded a new Siteprofile, including the latest ProcessWire 2.4.2 from todays dev branch.

The profile include tests for ImageSizer and ImagickResizer for the following categories:

  • cms
  • crop
  • formats
  • gamma
  • scale
  • sharpen
  • others

The module for extending the images naming scheme (PageimageNamingScheme) is included too.

Link to comment
Share on other sites

Uploaded version 0.1.7 to github

 

- added handling for gamma correction when gamma reading seems to be not available.

 

    With some versions of Imagick the function getImageGamma() returns 0 for all images.

    Don't know why, but have changed the code to asume a Gamma of 2.2 in those cases. :mellow:

  • Like 1
Link to comment
Share on other sites

  • 6 months later...

Hi,

actually no. Imagick is a PHP_extension that is used as layer between PHP and ImageMagick, this way ImageMagick can be used on shared hosts without the use of the exec() function. I don't know graphicsmagick, only have heard the name. Is it used by calling through exec(), like ImageMagick, NETPBM, and others?

Horst

Link to comment
Share on other sites

  • 4 months later...

Hello,

i really like this work, but i cannot get it running:

am i getting this right:  some hosts have ImageMagick installed, but do not allow php_extensions and php.ini changes if i use their managed hosting - so this module won't work? or is there way to get this working? they tell me that imagemagick is running this way for typo3... ?!

thanks

Link to comment
Share on other sites

This module also isn't compatible with PW 2.5, because there were many changes in the ImageSizer and Pageimages modules after this was built.

About what the providers allow or not I cannot say much. At least my knowing is that mostly all PHP installations have GD lib (bundled). Then on second place much of them have IMagick installed / enabled, because it is a PHP-extension that acts as a wrapper / proxy between the customers php scripts and the ImageMagick-Application. This is because on shared hosts mostly the exec(), system(), passthrough() functions are disabled for security reasons. But to trigger ImageMagick you would need exec().

The support for IMagick is like zero. I have one issue pending (regarding not detecting transparency in one sort of PNGs), I couldn't find any helpful answer. :(

And even if you found a running installation of IMagick, the different IMagick / ImageMagick Versions look like a hell to me. There are plenty function one need to query infos about the loaded image but they simply doesn't return anything. It looked to me that some of those functions are only implemented as placeholders, returning simply nothing in regard of the actual images. :(

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...