Jump to content

Recommended Posts

What's the best way to deal with this error?

Fatal error: Uncaught ValueError: imagecolorsforindex(): Argument #2 ($color) is out of range

PHP 8 has changed the behavior of the shutup operator - it no longer silences fatal errors.

 


The water in a vessel is sparkling; the water in the sea is dark. The small truth has words which are clear; the great truth has great silence.

- Rabindranath Tagore

Share this post


Link to post
Share on other sites
On 10/5/2021 at 12:52 AM, Smoky Barnable said:

What's the best way to deal with this error?

Fatal error: Uncaught ValueError: imagecolorsforindex(): Argument #2 ($color) is out of range

PHP 8 has changed the behavior of the shutup operator - it no longer silences fatal errors.

 

For those of you who would like to use this addon with PHP 8 the following change cleared this fatal error.

In the image.php file, change:

$trnprt_color = @imagecolorsforindex ( $this->_image, $trnprt_indx );

to:

if ($trnprt_indx < imagecolorstotal($this->_image)){
        		   $trnprt_color = imagecolorsforindex ( $this->_image, $trnprt_indx );
				  }

 


The water in a vessel is sparkling; the water in the sea is dark. The small truth has words which are clear; the great truth has great silence.

- Rabindranath Tagore

Share this post


Link to post
Share on other sites
On 9/27/2021 at 1:43 AM, Smoky Barnable said:

I have this mostly working with PHP8 except for this warning:

Deprecated: Required parameter $quality follows optional parameter $save_in in /home/includes/modules/kiss_image_thumbnailer/classes/Image.php on line 137


    protected function _output( $save_in = null, $quality, $filters = null ) {
      switch ($this->_mime_type) {
        case self::IMAGETYPE_GIF :
          return imagegif ( $this->_image, $save_in );
          break;
        case self::IMAGETYPE_JPEG :
        case self::IMAGETYPE_JPG :
          $quality = is_null ( $quality ) ? 75 : $quality;
          return imagejpeg ( $this->_image, $save_in, $quality );
          break;
        case self::IMAGETYPE_PNG :
          $quality = 9;
          $filters = is_null ( $filters ) ? null : $filters;
          return imagepng ( $this->_image, $save_in, $quality, $filters );
          break;
        default :
          trigger_error ( 'Image cannot be created.', E_USER_NOTICE );
          break;
      } // end switch
    } // end method

I see this warning in the "what's new?" box.

    protected function _output( $quality, $save_in = null, $filters = null ) {
      switch ($this->_mime_type) {
        case self::IMAGETYPE_GIF :
          return imagegif ( $this->_image, $save_in );
          break;
        case self::IMAGETYPE_JPEG :
        case self::IMAGETYPE_JPG :
          $quality = is_null ( $quality ) ? 75 : $quality;
          return imagejpeg ( $this->_image, $quality, $save_in );
          break;
        case self::IMAGETYPE_PNG :
          $quality = is_null ( $quality ) ? 0 : $quality;
          $filters = is_null ( $filters ) ? null : $filters;
          return imagepng ( $this->_image, $quality, $save_in, $filters );
          break;
        default :
          trigger_error ( 'Image cannot be created.', E_USER_NOTICE );
          break;

This works for me.

Share this post


Link to post
Share on other sites

I change the order of the parameters:

    protected function _output( $quality, $save_in = null, $filters = null ) {

and

          return imagejpeg ( $this->_image, $quality, $save_in );

and

          return imagepng ( $this->_image, $quality, $save_in, $filters );

 

Share this post


Link to post
Share on other sites

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

×