Get the most out of your Centmin Mod LEMP stack
Become a Member

Sysadmin [optimise-images.sh] Imagick fails to convert png to webp (sometimes)

Discussion in 'System Administration' started by Volodymyr Lupu, Jan 15, 2020.

  1. Volodymyr Lupu

    Volodymyr Lupu New Member

    6
    1
    3
    Dec 12, 2017
    Ratings:
    +2
    Local Time:
    2:56 PM
    Please fill in any relevant information that applies to you:
    • CentOS Version: CentOS 7 64bit
    • Centmin Mod Version Installed: 123.09beta01
    • Nginx Version Installed: 1.15.10
    • Persistent Config: Do you have any persistent config file options set in /etc/centminmod/custom_config.inc ?
      Code (Text):
      LIBRESSL_SWITCH='n'
      CLANG='n'
      DEVTOOLSETSIX='n'
      DEVTOOLSETSEVEN='y'
      DEVTOOLSETEIGHT='n'
      NGINX_DEVTOOLSETGCC='y'
      GCCINTEL_PHP='y'
      PHP_PGO='y'
      VHOSTCTRL_CLOUDFLAREINC='y'
      NSD_INSTALL='n'
      NGINX_DYNAMICTLS='y'
      CLOUDFLARE_ZLIB='y'
      CLOUDFLARE_ZLIBPHP='y'
      OPENSSLECDSA_PATCH='y'
      OPENSSL_VERSION='1.1.1b'
      LIBRESSL_SWITCH='n'
      MARIADB_INSTALLTENTHREE='y'
      


      No error message in the console, generates the supposed file size decrease normally, however it either fails to save the file properly or fails midway conversion. Anyone know how to solve this?

      (I dont understand anything about "webp:method" and "png:compression-strategy" so I'm not sure if changing these values may change anything)
      https://i.imgur.com/EIoiC4I.png
     
    Last edited: Jan 15, 2020
  2. eva2000

    eva2000 Administrator Staff Member

    44,520
    10,165
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,737
    Local Time:
    11:56 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    how was optimise-images.sh setup centminmod/optimise-images ?

    instead of screenshots use copy/paste test into gist.github.com or pastebin text file for your script's run/output
     
  3. eva2000

    eva2000 Administrator Staff Member

    44,520
    10,165
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,737
    Local Time:
    11:56 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    I just tested your provided png file and worked fine for me converting to webp + optimising png file itself

    first profile the png file which reports as 508KB in size
    Code (Text):
    ./optimise-images.sh profile /home/volod-testpng-webp
    ------------------------------------------------------------------------------
    image profile
    image name : width : height : quality : transparency : image depth (bits) : size : user: group
    ------------------------------------------------------------------------------
    images in /home/volod-testpng-webp
    logged at /home/optimise-logs/profile-log-150120-044726.log
    ------------------------------------------------------------------------------
    image : bx108617-PgoYLgWzzm0c.png : 460 : 652 : 92 : True : 8 : 519963 : root : root
    ------------------------------------------------------------------------------
    Original or Existing Images:
    ------------------------------------------------------------------------------
    | Avg width | Avg height | Avg quality | Avg size   | Total size (Bytes) | Total size (KB) |
    | --------- | ---------- | ----------- | --------   | ------------------ | --------------- |
    | 460       | 652        | 92          | 519963     | 519963             | 508             |
    ------------------------------------------------------------------------------
    ImageMagick Resource Limits
    ------------------------------------------------------------------------------
    Version: ImageMagick 6.9.10-86 Q16 x86_64 2020-01-13
    Resource limits:
      Width: 214.7MP
      Height: 214.7MP
      List length: unlimited
      Area: 67.054GP
      Memory: 31.2243GiB
      Map: 62.4487GiB
      Disk: unlimited
      File: 196608
      Thread: 4
      Throttle: 0
      Time: unlimited
    ------------------------------------------------------------------------------
    Completion Time: 0.03 seconds
    ------------------------------------------------------------------------------
    

    then ran optimise with webP variable IMAGICK_WEBP='y' enabled
    Code (Text):
    ./optimise-images.sh optimise /home/volod-testpng-webp
    !!! Important !!!
    Have you made a backup of images in /home/volod-testpng-webp? [y/n]: y
    ------------------------------------------------------------------------------
    image optimisation start
    ------------------------------------------------------------------------------
    ### bx108617-PgoYLgWzzm0c.png (png) ###
    /bin/nice -n 10 /usr/bin/ionice -c2 -n7 /usr/bin/convert -define registry:temporary-path=/home/imagicktmp bx108617-PgoYLgWzzm0c.png -interlace none -strip -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=2             -write mpr:bx108617-PgoYLgWzzm0c -resize 2048x2048\> -write bx108617-PgoYLgWzzm0c.png +delete             mpr:bx108617-PgoYLgWzzm0c -define webp:thread-level=1 -define webp:method=4 -define webp:alpha-quality=100 -define webp:lossless=false -quality 75 -resize 2048x2048\> bx108617-PgoYLgWzzm0c.png.webp
    webp image size smaller than original 45420 < 519963
    /bin/nice -n 10 /usr/bin/ionice -c2 -n7 optipng -o2 bx108617-PgoYLgWzzm0c.png -preserve -out bx108617-PgoYLgWzzm0c.png
    Output IDAT size = 460559 bytes (118466 bytes decrease)
    Output file size = 460616 bytes (118670 bytes = 20.49% decrease)
    ------------------------------------------------------------------------------
    Completion Time: 0.96 seconds
    ------------------------------------------------------------------------------
    ------------------------------------------------------------------------------
    image profile
    image name : width : height : quality : transparency : image depth (bits) : size : user: group
    ------------------------------------------------------------------------------
    images in /home/volod-testpng-webp
    logged at /home/optimise-logs/profile-log-150120-044731.log
    ------------------------------------------------------------------------------
    image : bx108617-PgoYLgWzzm0c.png : 460 : 652 : 92 : False : 8 : 460616 : root : root
    image : bx108617-PgoYLgWzzm0c.png.webp : 460 : 652 : 92 : False : 8 : 45420 : root : root
    ------------------------------------------------------------------------------
    Original or Existing Images:
    ------------------------------------------------------------------------------
    | Avg width | Avg height | Avg quality | Avg size   | Total size (Bytes) | Total size (KB) |
    | --------- | ---------- | ----------- | --------   | ------------------ | --------------- |
    | 460       | 652        | 92          | 460616     | 460616             | 450             |
    ------------------------------------------------------------------------------
    Optimised WebP Images:
    ------------------------------------------------------------------------------
    | Avg width | Avg height | Avg quality | Avg size   | Total size (Bytes) | Total size (KB) |
    | --------- | ---------- | ----------- | --------   | ------------------ | --------------- |
    | 460       | 652        | 92          | 45420      | 45420              | 44              |
    ------------------------------------------------------------------------------
    ImageMagick Resource Limits
    ------------------------------------------------------------------------------
    Version: ImageMagick 6.9.10-86 Q16 x86_64 2020-01-13
    Resource limits:
      Width: 214.7MP
      Height: 214.7MP
      List length: unlimited
      Area: 67.054GP
      Memory: 31.2243GiB
      Map: 62.4487GiB
      Disk: unlimited
      File: 196608
      Thread: 4
      Throttle: 0
      Time: unlimited
    ------------------------------------------------------------------------------
    Completion Time: 0.04 seconds
    ------------------------------------------------------------------------------
    

    afterwards, optimised png file + webp version created where png is now 450KB optimised size and webP version is 45KB in size
    Code (Text):
    ls -lah /home/volod-testpng-webp/                   
    total 508K
    drwxr-xr-x   2 root root 4.0K Jan 15 04:47 .
    drwxr-xr-x. 43 root root 4.0K Jan 15 04:36 ..
    -rw-rw-r--   1 root root 450K Jan 15 04:47 bx108617-PgoYLgWzzm0c.png
    -rw-r--r--   1 root root  45K Jan 15 04:47 bx108617-PgoYLgWzzm0c.png.webp
    

    same with optimise-cron-age mode
    Code (Text):
    ./optimise-images.sh optimise-cron-age /home/volod-testpng-webp
    !!! Important !!!
    Have you made a backup of images in /home/volod-testpng-webp? [y/n]: y
    ------------------------------------------------------------------------------
    image optimisation start
    ------------------------------------------------------------------------------
    ### bx108617-PgoYLgWzzm0c.png (png) ###
    /bin/nice -n 10 /usr/bin/ionice -c2 -n7 /usr/bin/convert -define registry:temporary-path=/home/imagicktmp bx108617-PgoYLgWzzm0c.png -interlace none -strip -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=2             -write mpr:bx108617-PgoYLgWzzm0c -resize 2048x2048\> -write bx108617-PgoYLgWzzm0c.png +delete             mpr:bx108617-PgoYLgWzzm0c -define webp:thread-level=1 -define webp:method=4 -define webp:alpha-quality=100 -define webp:lossless=false -quality 75 -resize 2048x2048\> bx108617-PgoYLgWzzm0c.png.webp
    webp image size smaller than original 45420 < 519963
    /bin/nice -n 10 /usr/bin/ionice -c2 -n7 optipng -o2 bx108617-PgoYLgWzzm0c.png -preserve -out bx108617-PgoYLgWzzm0c.png
    Output IDAT size = 460559 bytes (118466 bytes decrease)
    Output file size = 460616 bytes (118670 bytes = 20.49% decrease)
    ------------------------------------------------------------------------------
    Completion Time: 0.95 seconds
    ------------------------------------------------------------------------------
    

    Code (Text):
    ls -lah /home/volod-testpng-webp/                            
    total 508K
    drwxr-xr-x   2 root root 4.0K Jan 15 04:54 .
    drwxr-xr-x. 43 root root 4.0K Jan 15 04:36 ..
    -rw-rw-r--   1 root root 450K Jan 15 04:54 bx108617-PgoYLgWzzm0c.png
    -rw-r--r--   1 root root  45K Jan 15 04:54 bx108617-PgoYLgWzzm0c.png.webp
    

    I can't reproduce your problem on my end for this file at least. Tested with optimise-images.sh v4.8 from centminmod/optimise-images
     
  4. eva2000

    eva2000 Administrator Staff Member

    44,520
    10,165
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,737
    Local Time:
    11:56 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    If you're using old version of optimise-images.sh to update, if you installed via
    Code (Text):
    mkdir -p /root/tools
    cd /root/tools
    git clone --depth=1 https://github.com/centminmod/optimise-images
    

    then to update
    Code (Text):
    cd /root/tools/optimise-images
    # backup existing edited optimise-image.sh with datetime stamp
    cp -a optimise-images.sh optimise-images.sh-$(date +"%d%m%y-%H%M%S")
    git stash
    git pull
    

    then to compare your previous modifications to updated optimise-images.sh where date timestamp of your back up is say 150120-192519
    Code (Text):
    cd /root/tools/optimise-images
    diff -u optimise-images.sh-150120-192519 optimise-images.sh
    

    But optimise-images.sh is provided as is without support generally as it isn't part of Centmin Mod LEMP stack but script I wrote standalone at centminmod/optimise-images
     
  5. Volodymyr Lupu

    Volodymyr Lupu New Member

    6
    1
    3
    Dec 12, 2017
    Ratings:
    +2
    Local Time:
    2:56 PM
    Managed to make it work. Optimise-images had nothing to do with it, although it was slightly outdated it was not causing the error.

    The issue was that I was running an old version of ImageMagick: 6.9.XX
    After compiling the latest version (7.0.9-16) everything worked perfectly.

    Sorry for the bother George and thank you for the help :)
     
  6. eva2000

    eva2000 Administrator Staff Member

    44,520
    10,165
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,737
    Local Time:
    11:56 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    strange i used ImageMagick 6.9 for above tests and it worked. But if it works for you :)