Unwanted black background on rotated image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Jmess
Posts: 7
Joined: 2013-04-20T13:08:11-07:00
Authentication code: 6789

Unwanted black background on rotated image

Post by Jmess »

I have scoured the net for a working solution to my issue but have not yet found one. I am working with jpg images and applying a rotation to output a png with transparency. I seem to be getting a black background layer that is rotated approximately half the designated rotation angle on the sides only and solid black on the top and bottom of the image. See website example here: http://www.studentrent.com/imagerotate.php

The page includes the imagemagick version information as well as the code used to produce the images. There are two images the first is a simple manipulation without -rotate to show that the code is working. The second includes the -rotate command and demonstrates result.

This example is hosted on godaddy on a shared linux host.

Any insight will be much appreciated.
Thank you!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Unwanted black background on rotated image

Post by snibgo »

1. Your commands are complex. Can you isolate the problem so anyone can test?

2. You have a space after "PNG32:". It shouldn't have a space.

3. Your IM version is very old. Perhaps it's an old bug.
snibgo's IM pages: im.snibgo.com
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Unwanted black background on rotated image

Post by Bonzo »

This works for me on a newer version of Imagemagick so it could be a version problem as snibgo said:

Code: Select all

<?php
$cmd = " -bordercolor white -border 6 -bordercolor grey60 -border 1 -background black".
" /( +clone -shadow 60x4+4+4 /) -background none +swap -flatten -rotate 10 ";

exec("/usr/bin/convert units/1018-0.jpg $cmd PNG32:output_image.png"); 
?>
You also has another problem looking at your second image that this is fixing.
Jmess
Posts: 7
Joined: 2013-04-20T13:08:11-07:00
Authentication code: 6789

Re: Unwanted black background on rotated image

Post by Jmess »

Thank you for your quick replies. I have simplified the example code and added another version similar to Bonzo's recommended approach. Still no luck. Unfortunately I am on Godaddy's shared host so updating the IM version is not possible. I recently upgraded my hosting plan and had no such issues with my previous hosting plan which had the same version of IM that I am currently using. Please note that if I include a "-background blue" or similar the results are as expected.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Unwanted black background on rotated image

Post by snibgo »

Check your code very, very carefully.

Your second example has a shadow around the black edges even though you claim the code that makes it has no "-shade" or "-shadow".

You might also provide the source file "1018-0.jpg".
snibgo's IM pages: im.snibgo.com
Jmess
Posts: 7
Joined: 2013-04-20T13:08:11-07:00
Authentication code: 6789

Re: Unwanted black background on rotated image

Post by Jmess »

I verified that the code description below the image is exactly the code used to create the image. I also added the original image at the top with no modification.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Unwanted black background on rotated image

Post by fmw42 »

You might try adding -matte -channel RGBA before -background none.

But I suspect you Godaddy version of IM is just too old to allow control of the -rotate background or there is a bug in that version.

What version of IM is Godaddy using on your site? I am on Godaddy, but it has IM 6.2.8. Another user on Godaddy is using a newer version though still old at 6.5.4.7. I think it depends upon what server you are on at Godaddy. But you might ask them to move you if you are using IM 6.2.8.

Try

<?php
echo "<pre>";
system("type -a convert");
echo "</pre>";
?>

to see what where IM is located and then once you know, edit the following for the correct path (usually either /usr/bin or /usr/local/bin)

<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>
Jmess
Posts: 7
Joined: 2013-04-20T13:08:11-07:00
Authentication code: 6789

Re: Unwanted black background on rotated image

Post by Jmess »

Version: ImageMagick 6.5.4-7 2012-05-07 Q16 OpenMP
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Unwanted black background on rotated image

Post by snibgo »

The oldest version I have is 6.5.8-8, on Windows 7. From the command line, ...

Code: Select all

convert 1018-0.jpg -background None -rotate 20 out.png
... works fine, creating four transparent triangles. If I exclude "-background None", I get four black triangles, as I would expect.

I notice that one of your images is rotated by only 10 degrees. Something weird is happening.
snibgo's IM pages: im.snibgo.com
Jmess
Posts: 7
Joined: 2013-04-20T13:08:11-07:00
Authentication code: 6789

Re: Unwanted black background on rotated image

Post by Jmess »

Ok, so as expected Godaddy is less than helpful. Apparently everything is operational on there end... So is anybody operating on Godaddy's shared grid hosting that has a working example of rotate or Polaroid working?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Unwanted black background on rotated image

Post by Bonzo »

I know it is a pain but there are plenty of other hosting companys; if you need to use this code I would look elsewhere and see what version they have.

The strange thing is I am sure it used to work for me on 6.3.5 What happens if you remove the PNG32: as I never use that.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Unwanted black background on rotated image

Post by fmw42 »

There is a bug in IM 6.5.4.7 for rotate with transparency.

I have access to Godaddy at 6.5.4.7 and tried the following with and without all the various settings and always get the following. It works fine with color background but not transparent. Note that some of the background is transparent, while some is black.

<?php
exec("/usr/bin/convert zelda3.jpg -matte -channel RGBA -virtual-pixel background -background none -rotate 20 PNG32:zelda3_rot20.png 2>&1",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>

Input:
Image

Result:
Image


I think you are not going to get around this on Godaddy, unless they upgrade IM to a reasonably new version.
Jmess
Posts: 7
Joined: 2013-04-20T13:08:11-07:00
Authentication code: 6789

Re: Unwanted black background on rotated image

Post by Jmess »

New info... I uploaded the same files to another host that I have access to on Godaddy in a legacy server set up running Version: ImageMagick 5.5.6 04/01/03 Q16 and the images were manipulated successfully! So this does suggest that there are issues with the Version: ImageMagick 6.5.4-7 2012-05-07 Q16 at least in the server environment that I'm in. Option 1: Get Godaddy to update their IM (would require an IM exec to detail the issue with Godaddy). Option 2: Don't use rotate or Polaroid features if transparent background is needed. Option 3: Change host. Any other ideas? Thanks for all the input so far!
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Unwanted black background on rotated image

Post by Bonzo »

Could you modify the image on the other server and copy it over to the 6.5.4 server or link to the image on the 5.5.6 server?

I am told you may be able to install Imagemagick into your server as any other program but have never tried it.
Jmess
Posts: 7
Joined: 2013-04-20T13:08:11-07:00
Authentication code: 6789

Re: Unwanted black background on rotated image

Post by Jmess »

Bonzo, I could probably do that however it would be quite inconvenient as the images being processed are uploaded by users in real time and cross referencing domains is not ideal. Ultimately I aim to use the Polaroid feature available in the newer release however it has the same issues with the black background.
Regarding installing an updated version into my account, I'm all ears! Has anybody done this successfully? I am more than willing to try. Anybody have directions for doing this? Thank you.
Post Reply