Page 1 of 1

Rotate Changes Transparency to Black

Posted: 2012-06-08T11:10:48-07:00
by jman
I'm really sorry if this is a stupid mistake on my part but I swear I read about this and tried every combo of commands I could. First off....the command in shell and exec works perfectly....

Code: Select all

convert -verbose ".$input." -background none -rotate 45 ".$ouput
however attempting it with imagick with various versions of the following code produces a rotated image with the transparency turned black (see before/after images attached).

Code: Select all

$temp_user_image = new Imagick();
$temp_user_image->readImage(config::PUBLIC_HTML."sketch/sketchDefault3/maskBelly.png");
$temp_user_image->setBackgroundColor(new ImagickPixel('transparent'));
$temp_user_image->setImageAlphaChannel(imagick::ALPHACHANNEL_TRANSPARENT);
$temp_user_image->setImageMatte(1); 
$temp_user_image->rotateImage(new ImagickPixel('transparent'), 30);
$temp_user_image->setImageFormat("png32");  	
$temp_user_image->writeImage(config::PUBLIC_HTML."sketch/sketchDefault3/maskBelly2.png");
I'd really appreciate any help you could provide.

Versions:
ImageMagick 6.7.7-6 2012-06-07 Q16
PEAR Version: 1.9.4
PHP Version : 5.2.17
imagick: 3.0.1

Re: Rotate Changes Transparency to Black

Posted: 2012-06-08T13:15:04-07:00
by fmw42
I am not an expert on Imagick, but try

$temp_user_image = new Imagick();
$temp_user_image->readImage(config::PUBLIC_HTML."sketch/sketchDefault3/maskBelly.png");
$temp_user_image->rotateImage(new ImagickPixel('none'), 30);
$temp_user_image->setImageFormat("png32");
$temp_user_image->writeImage(config::PUBLIC_HTML."sketch/sketchDefault3/maskBelly2.png");

Re: Rotate Changes Transparency to Black

Posted: 2012-06-08T14:04:20-07:00
by Bonzo
This works OK for me - although needs triming and repaging.

Code: Select all

$im = new Imagick('before.png');
$im->rotateImage(new ImagickPixel('none'), 30); 
$im->writeImage('rotated.png'); 
$im->destroy();
Image

There could be something wrong with your version; you could be confusing imagick with to much code?

I used Imagick API version 1608 on a linux server

Re: Rotate Changes Transparency to Black

Posted: 2012-06-08T17:16:53-07:00
by jman
I tried both of your suggestions and both are producing the same situation...

If it matters I am running Centos 6.2 and pecl info imagick returns....

Code: Select all

ABOUT PECL.PHP.NET/IMAGICK-3.0.1
================================
Release Type          PECL-style PHP extension (source code)
Name                  imagick
Channel               pecl.php.net
Summary               Provides a wrapper to the ImageMagick library.
Description           Imagick is a native php extension to create and
                      modify images using the ImageMagick API.
                      This extension requires ImageMagick version
                      6.2.4+ and PHP 5.1.3+.

                      IMPORTANT: Version 2.x API is not compatible
                      with earlier versions.
Maintainers           Mikko Koppanen <mkoppanen@php.net> (lead)
                      Scott MacVicar <scottmac@php.net> (lead)
Release Date          2010-11-18 21:16:01
Release Version       3.0.1 (stable)
API Version           3.0.1 (stable)
License               PHP License (http://www.php.net/license)
Release Notes         - Fixed PECL bug #17244
Required Dependencies PHP version 5.1.3
                      PEAR installer version 1.4.0 or newer
package.xml version   2.0
Last Modified         2012-06-08 18:48
Previous Installed    - None -

Re: Rotate Changes Transparency to Black

Posted: 2012-06-08T17:31:31-07:00
by fmw42
You are not running the latest version of Imagick. It is 3.1.x (but has not been upgraded in a while). Not sure where you can get it but try a google search. Or check with your ISP.

P.S.

see
http://pecl.php.net/package/imagick/3.1.0RC1

Re: Rotate Changes Transparency to Black

Posted: 2012-06-08T17:54:06-07:00
by magick

Re: Rotate Changes Transparency to Black

Posted: 2012-06-10T08:15:49-07:00
by jman
I installed 3.1.0RC2, ran the image test with all above suggestions and my own code and still producing black background.

Re: Rotate Changes Transparency to Black

Posted: 2012-06-10T10:00:04-07:00
by Bonzo
It is not something daft like the image was changed in some way when uploading it? Have you tried the image in this thread? Have you tried any other images?

Re: Rotate Changes Transparency to Black

Posted: 2012-06-10T11:08:13-07:00
by fmw42
You are not using JPG for output are you? If so, it does not support transparency. Just checking.

Re: Rotate Changes Transparency to Black

Posted: 2012-06-13T09:40:40-07:00
by DJ Mike
In your test you use:

$temp_user_image->setImageFormat("png32");

I used

$image->setimageformat("gif");

and didn't need to set BGcolor or alpha

Maybe try

$temp_user_image->setImageFormat("png");

Code: Select all

<?php
$image = new Imagick("opossum.jpg"); 
$image->rotateimage("transparent",30);
# make it a gif for transparency
$image->setimageformat("gif");
header("Content-type: image/gif");
echo $image;
?>
Imagick::rotateImage
http://eclecticdjs.com/mike/tutorials/p ... rotate.php