1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fixed XenForo_Image_ImageMagick_Pecl and transparency

Discussion in 'Resolved Bug Reports' started by Ralle, May 25, 2016.

  1. Ralle

    Ralle Active Member

    Considering you decided to solve it for GD, here it is for Imagick.

    Transparency in GIF and PNG are not persisted when resizing images. In fact, a transparent background becomes black for one one type and white for the another.

    I wrote a little addon that extends the class XenForo_Image_ImageMagick_Pecl class:
    PHP:
    <?php

    class Ranimavatars_Imagick extends XFCP_Ranimavatars_Imagick
    {
        protected function 
    __construct(Imagick $image)
        {
            
    $image->setImageBackgroundColor(new ImagickPixel('transparent'));
            
    $image->setImageAlphaChannel(imagick::ALPHACHANNEL_REMOVE);
            
    $image->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
            
    parent::__construct($image);
        }
    }
    But I think it makes more sense to make it part of XenForo.

    It will make sure that transparency is kept when working with PNG and GIF.
     
    AndyB likes this.
  2. The Forum Heroes

    The Forum Heroes Well-Known Member

    Thanks!
     
    Ralle likes this.
  3. Ralle

    Ralle Active Member

    People have asked for my addon while we wait for the developers' decision. Here it is.

    EDIT: Apparently it requires a pretty recent version of Imagick, you can replace the constant Imagick::ALPHACHANNEL_REMOVE with 11 to be a little more backwards compatible. More information...
     

    Attached Files:

    Last edited: May 27, 2016
    SneakyDave likes this.
  4. Mike

    Mike XenForo Developer Staff Member

    This is again image specific as I'm unable to reproduce it with any test image that I have. Can you provide a reproduction case image?
     
  5. Ralle

    Ralle Active Member

    Let's see. I have attached two images:

    Imagick:

    99.png gets a white background
    99.gif gets a black background

    GD:

    99.gif gets a white background
    99.png gets transparent background

    But only for avatars.

    My patch fixes Imagick, but there seems to also be a problem with GD.
     

    Attached Files:

    • 99.gif
      99.gif
      File size:
      15.6 KB
      Views:
      13
    • 99.png
      99.png
      File size:
      24 KB
      Views:
      14
  6. Mike

    Mike XenForo Developer Staff Member

    I can reproduce the GD issue mentioned there and I have a workaround for that.

    However, I can't reproduce any Imagick issues. We've tried 3 different versions of the Imagick PECL extensions with different versions of ImageMagick itself (on different systems/OSes) and they output both images with a transparent background in all our cases.

    What version of Imagick and ImageMagick are you using?
     
  7. Ralle

    Ralle Active Member

    Code:
    root@f88fc3117404:/tmp/hive2# php --ri imagick
    
    imagick
    
    imagick module => enabled
    imagick module version => 3.4.0
    imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
    Imagick compiled with ImageMagick version => ImageMagick 6.8.9-9 Q16 x86_64 2016-01-17 http://www.imagemagick.org
    Imagick using ImageMagick library version => ImageMagick 6.8.9-9 Q16 x86_64 2016-02-02 http://www.imagemagick.org
    ImageMagick copyright => Copyright (C) 1999-2014 ImageMagick Studio LLC
    ImageMagick release date => 2016-02-02
    ImageMagick number of supported formats:  => 215
    ImageMagick supported formats => 3FR, AAI, AI, ART, ARW, AVI, AVS, BGR, BGRA, BIE, BMP, BMP2, BMP3, BRF, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CRW, CUR, CUT, DCM, DCR, DCX, DDS, DFONT, DJVU, DNG, DOT, DPX, DXT1, DXT5, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, EXR, FAX, FITS, FRACTAL, FTS, G3, GIF, GIF87, GRADIENT, GRAY, GROUP4, GV, HALD, HDR, HISTOGRAM, HRZ, HTM, HTML, ICB, ICO, ICON, INFO, INLINE, IPL, ISOBRL, JBG, JBIG, JNG, JNX, JPEG, JPG, JSON, K25, KDC, LABEL, M2V, M4V, MAC, MAP, MASK, MAT, MATTE, MEF, MIFF, MNG, MONO, MOV, MP4, MPC, MPEG, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NRW, NULL, ORF, OTB, OTF, PAL, PALM, PAM, PANGO, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, PPM, PREVIEW, PS, PS2, PS3, PSB, PSD, PTIF, PWP, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGBA, RGBO, RGF, RLA, RLE, RMF, RW2, SCR, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TTC, TTF, TXT, UBRL, UIL, UYVY, VDA, VICAR, VID, VIFF, VIPS, VST, WBMP, WMF, WMV, WMZ, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, YCbCr, YCbCrA, YUV
    
    Directive => Local Value => Master Value
    imagick.locale_fix => 0 => 0
    imagick.skip_version_check => 0 => 0
    imagick.progress_monitor => 0 => 0
    and
    Code:
    root@f88fc3117404:/tmp/hive2# convert --version
    Version: ImageMagick 6.8.9-9 Q16 x86_64 2016-02-02 http://www.imagemagick.org
    Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
    Features: DPC Modules OpenMP
    Delegates: bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib
    
    You can reproduce it in Docker:
    https://hub.docker.com/r/ralle/hive2base/~/dockerfile/
     
  8. Mike

    Mike XenForo Developer Staff Member

    I was unable to reproduce it with your Docker container either. It did pull down php-imagick 3.4.2, so I suppose that's relevant. ImageMagick itself is the same version, but the release dates also differ.

    I'm going to send you a test script to confirm that you can reproduce the issue there. It's a standalone version of some of the image manipulation classes and testing different permutations.
     
  9. Mike

    Mike XenForo Developer Staff Member

    After a while and some further clarification from @Ralle, we have managed to reproduce this. It looks like a temporary ImageMagick regression, but we have identified a workaround which will be included in the next release.
     
    SAS1024, Xon, eva2000 and 1 other person like this.

Share This Page