Tif with transparent background

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
btam

Tif with transparent background

Post by btam »

I have a tif image with transparent background.

I try to copy the image with the following code, the background color become white in the new image

$im = new Imagick('image.tif');
$im->setImageFormat("tif");
$im->writeImage('new_image.tif');

How to handle transparent tif image?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Tif with transparent background

Post by fmw42 »

try enabling the matte channel before writing
btam

Re: Tif with transparent background

Post by btam »

I've tried
$im->setImageMatte(true);
$im->setFormat("tiff");
$im->writeImage($image);

still no luck :(
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Tif with transparent background

Post by fmw42 »

what version of IM and what version of Imagick? perhaps you need to upgrade? I am not really an expert on Imagick, but I can see if it works for me.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Tif with transparent background

Post by fmw42 »

This works perfectly fine for me.

<?php

// Input image name
$image = "logo2t.tif";

// Output image name
$output = "logo2t2.tif";


try
{

$im = new Imagick();

$im->readImage( $image );

$im->writeImage( $output );

}

catch(Exception $e)
{
echo $e->getMessage();
}

// Delete the image created
//unlink($output);
echo "<img src=\"$output\" border=1>";

?>

But when I display the image to my browser, the transparent areas are white, because the background of the page is white. But when I copy the image to my desktop and display it in some other tool that is capable of showing the transparent areas, they look fine (transparent).


PHP Version 5.1.6
IM Version 6.6.2.9 Q16
Imagick 3.0.0RC1
Post Reply