yii2: Imagick PNG support check error.

G’day guys,

I could not find the root problem, but I thought I would post it here so its known about.

My host has imagick, but the ImageMagick supported formats are as follows ( from phpinfo() ):

3FR, AAI, AI, ART, ARW, AVI, AVS, BGR, BGRA, BMP, BMP2, BMP3, BRF, CAL, CALS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CRW, CUR, CUT, DCM, DCR, DCX, DDS, DNG, DOT, DPX, DXT1, DXT5, EPDF, EPT, EPT2, EPT3, ERF, EXR, FAX, FITS, FTS, G3, GIF, GIF87, GRADIENT, GRAY, GV, HALD, HDR, HISTOGRAM, HRZ, HTM, HTML, ICO, ICON, INFO, INLINE, IPL, ISOBRL, JNX, JPEG, JPG, JSON, K25, KDC, LABEL, M2V, M4V, MAC, MAP, MASK, MAT, MATTE, MEF, MIFF, MONO, MOV, MP4, MPC, MPEG, MPG, MRW, MSL, MTV, MVG, NEF, NRW, NULL, ORF, OTB, PALM, PANGO, PATTERN, PCD, PCDS, PCL, PCX, PDB, PDF, PDFA, PEF, PES, PJPEG, RADIAL-GRADIENT, RAF, RW2, SHTML, SR2, SRF, UBRL, WMV, X3F

You will notice no PNG in that list.

But the function below (from yiisoft/yii2/captcha/Captcha.php) returns “imagick”:

    public static function checkRequirements()
    {
        if (extension_loaded('imagick')) {
            $imagick = new \Imagick();
            $imagickFormats = $imagick->queryFormats('PNG');
            if (in_array('PNG', $imagickFormats)) {
                return 'imagick';
            }
        }
        if (extension_loaded('gd')) {
            $gdInfo = gd_info();
            if (!empty($gdInfo['FreeType Support'])) {
                return 'gd';
            }
        }
        throw new InvalidConfigException('Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required.');
    }

So you see even though I do not have support for PNG, it is thinking that I do. I have even tried adding exit(); above the return statement to see if that was the path it was taking, and it does indeed use that path.

But something else interesting is the following (inside requirements.php) sets $imagickMemo and $imagickOK stays false:

    if (extension_loaded('imagick')) {
        $imagick = new Imagick();
        $imagickFormats = $imagick->queryFormats('PNG');
        if (in_array('PNG', $imagickFormats)) {
            $imagickOK = true;
        } else {
            $imagickMemo = 'Imagick extension should be installed with PNG support in order to be used for image CAPTCHA.';
        }
    }

So you see, on the same system the same basic piece of code seems to give two different results, so I am thinking something else is also going on. I do notice the first one is using namespace where the other one does not.

As to the underlying cause, I wish you guys good luck, I have had to swap the code so GD evaluating happens first for it to work for me.

Peace, n099y.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

Your problem is not Yii2, is your imagick that has no support for PNG,

Your compile imagick, Example Centos:

yum remove ImageMagick yum install tcl-devel libpng-devel libjpeg-devel ghostscript-devel bzip2-devel freetype-devel libtiff-devel wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-6.6.3-5.tar.gz tar zxvf ImageMagick-6.6.3-5.tar.gz cd ImageMagick-6.6.3-5 ./configure --prefix=/usr/local --with-bzlib=yes --with-fontconfig=yes --with-freetype=yes --with-gslib=yes --with-gvc=yes --with-jpeg=yes --with-jp2=yes --with-png=yes --with-tiff=yes make clean make make install

Regards

sudo apt install php-gd

sudo service apache2 restart