AndyB
Well-known member
Hello,
In my Convert Image v4.2 add-on located here:
https://xenforo.com/community/resources/convert-image.2521/
I have the need to create a thumbnail. The issue I'm having is that when a .png image with a transparent background is converted to a .jpg image, the new .jpg image would turn the background to black, so I use this bit of code to change the background to white before creating the .jpg thumbnail.
	
	
	
		
This works fine on 99% of the servers the add-on is installed on, but some servers throw out this error:
	
	
	
		
The error is thrown by this line of code:
	
	
	
		
I have verified the setImageAlphaChannel is available using SSH:
	
	
	
		
and Imagick has been compiled against ImageMagick version 6.3.8 or newer.
Is there a better way to create thumbnails? Is there a XenForo function I can call to create a thumbnail image?
Thank you.
				
			In my Convert Image v4.2 add-on located here:
https://xenforo.com/community/resources/convert-image.2521/
I have the need to create a thumbnail. The issue I'm having is that when a .png image with a transparent background is converted to a .jpg image, the new .jpg image would turn the background to black, so I use this bit of code to change the background to white before creating the .jpg thumbnail.
		PHP:
	
	// check if image has transparency
if ($imagick->getImageAlphaChannel())
{
    // remove alpha channel
    $imagick->setImageAlphaChannel(11);
   
    // set image background color
    $imagick->setImageBackgroundColor('white');
    // merge layers
    $imagick->mergeImageLayers(imagick::LAYERMETHOD_FLATTEN);           
}This works fine on 99% of the servers the add-on is installed on, but some servers throw out this error:
		Code:
	
	ImagickException: Unable to set image alpha channelThe error is thrown by this line of code:
		PHP:
	
	$imagick->setImageAlphaChannel(11);I have verified the setImageAlphaChannel is available using SSH:
		Code:
	
	php --rc Imagick | grep -i setImageAlphaChanneland Imagick has been compiled against ImageMagick version 6.3.8 or newer.
Is there a better way to create thumbnails? Is there a XenForo function I can call to create a thumbnail image?
Thank you.
 
 
		 
 
		
