Rotate Changes Transparency to Black

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
jman
Posts: 3
Joined: 2012-06-08T10:58:47-07:00
Authentication code: 13

Rotate Changes Transparency to Black

Post 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
Attachments
After code run called maskBelly2
After code run called maskBelly2
after.png (22.15 KiB) Viewed 23699 times
Original prior to code run (called maskBelly.png)
Original prior to code run (called maskBelly.png)
before.png (15.94 KiB) Viewed 23699 times
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Rotate Changes Transparency to Black

Post 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");
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Rotate Changes Transparency to Black

Post 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
jman
Posts: 3
Joined: 2012-06-08T10:58:47-07:00
Authentication code: 13

Re: Rotate Changes Transparency to Black

Post 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 -
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Rotate Changes Transparency to Black

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Rotate Changes Transparency to Black

Post by magick »

jman
Posts: 3
Joined: 2012-06-08T10:58:47-07:00
Authentication code: 13

Re: Rotate Changes Transparency to Black

Post by jman »

I installed 3.1.0RC2, ran the image test with all above suggestions and my own code and still producing black background.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Rotate Changes Transparency to Black

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Rotate Changes Transparency to Black

Post by fmw42 »

You are not using JPG for output are you? If so, it does not support transparency. Just checking.
DJ Mike
Posts: 33
Joined: 2010-06-29T19:07:53-07:00
Authentication code: 8675308

Re: Rotate Changes Transparency to Black

Post 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
DJ Mike's Tutorials: PHP
ImageMagick Functions
http://eclecticdjs.com/mike/tutorials/p ... /index.php
Post Reply