Page 1 of 1

writeImages bug or not ?

Posted: 2018-03-27T14:24:14-07:00
by 2fast4you
I use Imagick with PHP on diff platforms:
1. mac os (2,6 GHz Intel Core i7, 16GB DDR3)
2. ubuntu 16.04 (i7-8700 CPU @ 3.20GHz, 64GB DDR3)

identify -versions
Version: ImageMagick 7.0.7-28 Q16 x86_64 2018-03-26 http://www.imagemagick.org
Copyright: © 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP
Delegates (built-in): bzlib djvu fontconfig freetype gvc jbig jng jpeg lcms lqr ltdl lzma openexr png tiff wmf x xml zlib

Hardware on ubuntu server is more powerful then on mac os.
But when I try to save GIF on ubuntu server it takes longer than on mac os.

Code: Select all

$imagick = $imagick->deconstructImages();
$imagick->writeImages($savePath, true);
I logged all methods and found that writeImages on ubuntu so slow.
For example: image with the same sizes can be saved for 1 second on mac os and little more than 2 seconds on ubuntu.

Can anybody help with this problem ?

Re: writeImages bug or not ?

Posted: 2018-03-27T14:29:26-07:00
by fmw42
Is OpenMP enabled on both systems? See Features from magick -version. Some Linux systems may be slower if using OpenMP. Try disabling it.

Is your Imagick using Imagemagick 7 and are they both compatible. For IM 7, use magick rather than convert. Also magick identify rather than identify.

Are you disk speeds the same?

Are your policy.xml files the same with regard to any restrictions or limitations of memory, etc?

Does the same happen if you use the command line or command line via PHP exec() rather than Imagick?

Re: writeImages bug or not ?

Posted: 2018-03-27T14:39:00-07:00
by 2fast4you
OpenMP is enabled on both systems.
Limits for ubuntu from php $imagick->getResourceLimit($type);

Code: Select all

imagick verions: Array
(
    [versionNumber] => 1799
    [versionString] => ImageMagick 7.0.7-28 Q16 x86_64 2018-03-26 http://www.imagemagick.org
)


HEIGHT: 107374182
WIDTH: 107374182
THREAD: 12
Area: 134939844608
Disk: -1
File: 768
Map: 134939844608
Memory: 67469922304
SSD on each platform. And images size not more than 500kb . I think it would be saved fast on hdd, too )
PHP is running with unlim memory.

convert command from console on server more faster than on mac os.

But I need saving only from php.
imagick module version 3.4.3 on both systems.

Re: writeImages bug or not ?

Posted: 2018-03-27T14:46:23-07:00
by fmw42
Sounds like an issue with Imagick.

Check your policy.xml files on both systems.

Code: Select all

find /usr -name policy.xml
to get the location/path

Code: Select all

cat path2/policy.xml
On my system it is at

/usr/local/etc/ImageMagick-6/policy.xml

or try

Code: Select all

convert -list policy

Re: writeImages bug or not ?

Posted: 2018-03-27T14:53:12-07:00
by fmw42
What format are you writing to in your output? Do you have the same versions of the delegate library for writing to that format in Imagemagick? e.g. libpng, or libtif or libjpeg

Re: writeImages bug or not ?

Posted: 2018-03-28T01:30:50-07:00
by 2fast4you
Output format - GIF
By default settings in both policy.xml are commented.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policymap [
  <!ELEMENT policymap (policy)+>
  <!ATTLIST policymap xmlns CDATA #FIXED ''>
  <!ELEMENT policy EMPTY>
  <!ATTLIST policy xmlns CDATA #FIXED '' domain NMTOKEN #REQUIRED
    name NMTOKEN #IMPLIED pattern CDATA #IMPLIED rights NMTOKEN #IMPLIED
    stealth NMTOKEN #IMPLIED value CDATA #IMPLIED>
]>
<!--
  Configure ImageMagick policies.

  Domains include system, delegate, coder, filter, path, or resource.

  Rights include none, read, write, execute and all.  Use | to combine them,
  for example: "read | write" to permit read from, or write to, a path.

  Use a glob expression as a pattern.

  Suppose we do not want users to process MPEG video images:

    <policy domain="delegate" rights="none" pattern="mpeg:decode" />

  Here we do not want users reading images from HTTP:

    <policy domain="coder" rights="none" pattern="HTTP" />

  Lets prevent users from executing any image filters:

    <policy domain="filter" rights="none" pattern="*" />

  The /repository file system is restricted to read only.  We use a glob
  expression to match all paths that start with /repository:

    <policy domain="path" rights="read" pattern="/repository/*" />

  Lets prevent users from executing any image filters:

    <policy domain="filter" rights="none" pattern="*" />

  Any large image is cached to disk rather than memory:

    <policy domain="resource" name="area" value="1GP"/>

  Define arguments for the memory, map, area, width, height and disk resources
  with SI prefixes (.e.g 100MB).  In addition, resource policies are maximums
  for each instance of ImageMagick (e.g. policy memory limit 1GB, -limit 2GB
  exceeds policy maximum so memory limit is 1GB).

  Rules are processed in order.  Here we want to restrict ImageMagick to only
  read or write a small subset of proven web-safe image types:

    <policy domain="delegate" rights="none" pattern="*" />
    <policy domain="filter" rights="none" pattern="*" />
    <policy domain="coder" rights="none" pattern="*" />
    <policy domain="coder" rights="read|write" pattern="{GIF,JPEG,PNG,WEBP}" />
-->
<policymap>
  <!-- <policy domain="system" name="shred" value="2"/> -->
  <!-- <policy domain="system" name="precision" value="6"/> -->
  <!-- <policy domain="system" name="memory-map" value="anonymous"/> -->
  <!-- <policy domain="system" name="max-memory-request" value="256MiB"/> -->
  <!-- <policy domain="resource" name="temporary-path" value="/tmp"/> -->
  <!-- <policy domain="resource" name="memory" value="2GiB"/> -->
  <!-- <policy domain="resource" name="map" value="4GiB"/> -->
  <!-- <policy domain="resource" name="width" value="10KP"/> -->
  <!-- <policy domain="resource" name="height" value="10KP"/> -->
  <!-- <policy domain="resource" name="list-length" value="128"/> -->
  <!-- <policy domain="resource" name="area" value="100MP"/> -->
  <!-- <policy domain="resource" name="disk" value="16EiB"/> -->
  <!-- <policy domain="resource" name="file" value="768"/> -->
  <!-- <policy domain="resource" name="thread" value="4"/> -->
  <!-- <policy domain="resource" name="throttle" value="0"/> -->
  <!-- <policy domain="resource" name="time" value="3600"/> -->
  <!-- <policy domain="coder" rights="none" pattern="MVG" /> -->
  <!-- <policy domain="delegate" rights="none" pattern="HTTPS" /> -->
  <!-- <policy domain="path" rights="none" pattern="@*" /> -->
  <!-- <policy domain="cache" name="memory-map" value="anonymous"/> -->
  <!-- <policy domain="cache" name="synchronize" value="True"/> -->
  <!-- <policy domain="cache" name="shared-secret" value="passphrase" stealth="true"/> -->
</policymap>
On ubuntu I tried modify settings, but it wasn't successful

Re: writeImages bug or not ?

Posted: 2018-03-28T09:29:50-07:00
by fmw42
You can only make the policy stricter. You cannot relax it. Your hosting provider will need to do that.

Sorry, I am at a loss to know what more to suggest

Re: writeImages bug or not ?

Posted: 2018-03-28T11:36:59-07:00
by snibgo
2fast4you wrote: Hardware on ubuntu server is more powerful then on mac os.

convert command from console on server more faster than on mac os.
So you have shown when using just ImageMagick, it runs faster on the faster machine.

So the problem is in IMagick or PHP, not in ImageMagick.

Re: writeImages bug or not ?

Posted: 2018-03-29T05:44:03-07:00
by 2fast4you

Code: Select all

$str = $imagick->getImagesBlob();
this method generate a string. And the time on ubuntu like a writeImages . But this method doesn't save anything.
Can imagick use file cache ? Or how enable cache only for virtual memory ?

Re: writeImages bug or not ?

Posted: 2018-06-27T03:31:22-07:00
by 2fast4you

Code: Select all

    function DrawSlides($width, $height) {
        $savePath = 'imagick.gif';
        $colors = [
            '#FFFAFA',
            '#6A5ACD',
            '#EE3B3B',
            '#4EEE94',
            '#7EC0EE',
            '#EEE685',
            '#FFA500',
            '#FAFAFA',
            '#FFA54F',
            '#242424',
            '#CD3333',
        ];

        $time = microtime(true);
        $backgroundColor = $colors[rand(0,10)];
        $imagick = new \Imagick();
        $imagick->newImage($width, $height, $backgroundColor);
        $imagick->setFormat('gif');
        $imagick->setImageFormat("gif");

        for($i = 0; $i < 50; $i++) {
            $backgroundColor = $colors[rand(0,10)];
            $tempImagick = new \Imagick();
            $tempImagick->newImage($width, $height, $backgroundColor);
            $tempImagick->setImageFormat("gif");

            $imagick->addImage($tempImagick);

        }
        $imagick = $imagick->deconstructImages();
        echo PHP_EOL . 'all draw generation = ' . round(microtime(true) - $time, 3) . ' seconds';
//        0.2 - 0.3 seconds

        $time = microtime(true);
        $str = $imagick->getImagesBlob();
//        OR
//      $imagick->writeImages($savePath, true);
        echo PHP_EOL . 'save image = ' . round(microtime(true) - $time, 3) . ' seconds';
//        1.7 - 2.0 seconds

    }
I work with gif pictures. Sometimes I need to resize, remove some slides or draw text. In example I draw 50 slides of gif image with different colors and sizes. When I draw image 1 x 1 pixels or 500 x 500 I get the same time of generation. How can it be ? When I draw picture more than 2000 x 2000 time of generation increases. But what the problem with the small sizes ?