Page 1 of 1
Unwanted black background on rotated image
Posted: 2013-04-20T13:19:36-07:00
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!
Re: Unwanted black background on rotated image
Posted: 2013-04-20T13:26:54-07:00
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.
Re: Unwanted black background on rotated image
Posted: 2013-04-20T14:04:55-07:00
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.
Re: Unwanted black background on rotated image
Posted: 2013-04-20T18:11:04-07:00
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.
Re: Unwanted black background on rotated image
Posted: 2013-04-20T18:58:57-07:00
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".
Re: Unwanted black background on rotated image
Posted: 2013-04-20T19:12:44-07:00
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.
Re: Unwanted black background on rotated image
Posted: 2013-04-20T19:34:38-07:00
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]);
?>
Re: Unwanted black background on rotated image
Posted: 2013-04-20T23:42:37-07:00
by Jmess
Version: ImageMagick 6.5.4-7 2012-05-07 Q16 OpenMP
Re: Unwanted black background on rotated image
Posted: 2013-04-21T00:37:02-07:00
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.
Re: Unwanted black background on rotated image
Posted: 2013-04-21T10:43:24-07:00
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?
Re: Unwanted black background on rotated image
Posted: 2013-04-21T11:23:03-07:00
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.
Re: Unwanted black background on rotated image
Posted: 2013-04-21T12:24:14-07:00
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:
Result:
I think you are not going to get around this on Godaddy, unless they upgrade IM to a reasonably new version.
Re: Unwanted black background on rotated image
Posted: 2013-04-21T13:26:59-07:00
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!
Re: Unwanted black background on rotated image
Posted: 2013-04-21T14:21:45-07:00
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.
Re: Unwanted black background on rotated image
Posted: 2013-04-21T14:43:59-07:00
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.