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?
Tif with transparent background
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Tif with transparent background
try enabling the matte channel before writing
Re: Tif with transparent background
I've tried
$im->setImageMatte(true);
$im->setFormat("tiff");
$im->writeImage($image);
still no luck
$im->setImageMatte(true);
$im->setFormat("tiff");
$im->writeImage($image);
still no luck
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Tif with transparent background
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Tif with transparent background
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
<?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