Jump to content

Recommended Posts

Posted

Hi, 

I'm running into the same problem. My setup is PW 3.0.120 on PHP 8.1. I tried all the recommendations above. There are no errors and log seems fine, but the resized gifs are not animated. The site I'm using it runs for quite a while now and the before the switch to PHP 8 and the latest PW version the resizing of gifs was working fine.

If there are any news on that pleas let me know. Thank you.

  • 3 months later...
Posted

Looks like the core module for resizing animated gifs doesn't work for PHP 8.

On the Production we have PW: 3.0.194 dev and PHP: 7.3.33-10+ubuntu18.04.1+deb.sury.org+1 and it is working there. Is it normal, that a resized animated gif gets bigger? The original was 1mb, the resized one 2mb. And the resized gif also had some 'artefacts/shadows' in it, and it also doesn't changed when adjusting quality from 90 to 100.

array(5) {
  ["filename"]=>
  string(88) "/home/www-data/xxxxxxxxx.net/site/assets/files/205849/xxxxxxx.gif"
  ["extension"]=>
  string(3) "gif"
  ["imageType"]=>
  int(1)
  ["info"]=>
  array(18) {
    ["width"]=>
    int(1200)
    ["height"]=>
    int(627)
    ["imageType"]=>
    int(1)
    ["mime"]=>
    string(9) "image/gif"
    ["orientation"]=>
    int(0)
    ["rotate"]=>
    int(0)
    ["flip"]=>
    int(0)
    ["channels"]=>
    int(3)
    ["bits"]=>
    int(8)
    ["gifversion"]=>
    string(6) "GIF89a"
    ["animated"]=>
    bool(true)
    ["delay"]=>
    int(4)
    ["trans"]=>
    bool(true)
    ["transcolor"]=>
    int(2)
    ["bgcolor"]=>
    int(2)
    ["numcolors"]=>
    int(256)
    ["interlace"]=>
    bool(false)
    ["appmarker"]=>
    array(0) {
    }
  }
  ["iptcRaw"]=>
  NULL
}
array(2) {
  [0]=>
  string(27) "ImageSizerEngineAnimatedGif"
  [1]=>
  string(18) "ImageSizerEngineGD"
}
string(14) "gif-trans-anim"




On the Dev Enviroment we have PW: 3.0.194 and PHP: 8.0.28 and there it isn't working/resizing.

array(5) {
  ["filename"]=>
  string(92) "/home/www-data/xxx.xxxxxx.net/site/assets/files/178453/xxxxxxx.gif"
  ["extension"]=>
  string(3) "gif"
  ["imageType"]=>
  int(1)
  ["info"]=>
  array(18) {
    ["width"]=>
    int(1200)
    ["height"]=>
    int(627)
    ["imageType"]=>
    int(1)
    ["mime"]=>
    string(9) "image/gif"
    ["orientation"]=>
    int(0)
    ["rotate"]=>
    int(0)
    ["flip"]=>
    int(0)
    ["channels"]=>
    int(3)
    ["bits"]=>
    int(8)
    ["gifversion"]=>
    string(6) "GIF89a"
    ["animated"]=>
    bool(true)
    ["delay"]=>
    int(4)
    ["trans"]=>
    bool(true)
    ["transcolor"]=>
    int(2)
    ["bgcolor"]=>
    int(2)
    ["numcolors"]=>
    int(256)
    ["interlace"]=>
    bool(false)
    ["appmarker"]=>
    array(0) {
    }
  }
  ["iptcRaw"]=>
  NULL
}
array(2) {
  [0]=>
  string(27) "ImageSizerEngineAnimatedGif"
  [1]=>
  string(18) "ImageSizerEngineGD"
}
string(14) "gif-trans-anim"


 

  • 8 months later...
Posted

Any news on that front? I have an images field on a page with a CKEditor field. When I add to that text content a gif from the images field, the gif gets resized and is not animated. I understand this is a bug that is yet to be fixed but is there a workaround in the meantime? Since I'm not displaying the images programmatically I cannot use the API e.g. Pageimage::getOriginal()  

  • Like 1
  • 1 year later...
Posted

Hi everyone,

I encountered the same issues with the ImageSizerEngineAnimatedGif and PHP 8 compatibility. The issues that prevented animated GIFs from being processed correctly.
The module works fine under PHP 7 but fails under PHP 8 due to changes in how GD handles image resources.

Issues Encountered

  1. GD Resource vs GdImage Object: PHP 8 changed GD image handling from resources to GdImage objects
  2. Array access on null values: Stricter type checking in PHP 8 caused "trying to access array offset on null" warnings
  3. File handling: Issues with fopen/fwrite combinations

Complete Fix Applied
Here are the changes to make the module PHP 8 compatible

Add new helper method (after line 42)

<?php
/**
 * Helper method to check if a variable is a valid GD image resource/object
 * Compatible with both PHP 7 (resource) and PHP 8 (GdImage object)
 * 
 * @param mixed $image
 * @return bool
 */
protected function isGdImage($image) {
    // PHP 8.0+ uses GdImage objects instead of resources
    if (class_exists('GdImage') && $image instanceof \GdImage) {
        return true;
    }
    // PHP 7.x uses resources
    return is_resource($image) && get_resource_type($image) === 'gd';
}

Update module version (line 26)

<?php
'version' => 2, // Increased for PHP 8 compatibility

Replace all GD resource checks

Line 176: if(!is_resource($frame)) → if(!$this->isGdImage($frame))
Line 178: if(!is_resource($bg)) → if(!$this->isGdImage($bg))
Line 205: if(!is_resource($nf)) → if(!$this->isGdImage($nf))
Line 234: if(isset($bg) && is_resource($bg)) → if(isset($bg) && $this->isGdImage($bg))
Line 235: if(isset($frame) && is_resource($frame)) → if(isset($frame) && $this->isGdImage($frame))
Line 236: if(isset($newimg) && is_resource($newimg)) → if(isset($newimg) && $this->isGdImage($newimg))
Line 271: if(!is_resource($frame)) → if(!$this->isGdImage($frame))
Line 275: if(is_resource($bg)) → if($this->isGdImage($bg))
Line 287: if(!is_resource($bg)) → if(!$this->isGdImage($bg))
Line 302: if(!is_resource($frame)) → if(!$this->isGdImage($frame))
Line 306: if(is_resource($bg)) → if($this->isGdImage($bg))
Line 318: if(!is_resource($bg)) → if(!$this->isGdImage($bg))
Line 335: if(!is_resource($nf)) → if(!$this->isGdImage($nf)) (This was the critical fix!)
Line 361: if(isset($bg) && is_resource($bg)) → if(isset($bg) && $this->isGdImage($bg))
Line 362: if(isset($frame) && is_resource($frame)) → if(isset($frame) && $this->isGdImage($frame))
Line 363: if(isset($newimg) && is_resource($newimg)) → if(isset($newimg) && $this->isGdImage($newimg))

Improve file handling (lines 223-225 and 348-350)

Replace:

<?php
$result = false === fwrite(fopen($srcFilename, 'wb'), $gifmerge->GetAnimation()) ? false : true;

width:

<?php
$handle = fopen($srcFilename, 'wb');
$result = $handle && fwrite($handle, $gifmerge->GetAnimation()) !== false;
if($handle) fclose($handle);

frame validation (around line 340):

<?php
if(count($frames) > 0) {
    $gifmerge = new ISEAG_GIFEncoder(
        // ... existing code
    );
    // ... file writing code
} else {
    $result = false;
}

The main issue was on line 335 where if(!is_resource($nf)) prevented PHP 8's GdImage objects from being recognized as valid frames. An empty frame arrays was passed to the GIF encoder, causing the errors in gif_encoder.php.

Hope this helps others who might encounter the same issues!

  • Like 1
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...