Page 1 of 1
Partial Image Pixelation Not Working
Posted: 2010-11-21T22:56:50-07:00
by mynatome
Hi,
I need to partially pixelate an image. I'm using the "Protect their Identity" example from here:
http://www.imagemagick.org/Usage/photos/#anonymity but I cannot get it to work.
I'm running this as a php exec. The code does work but it pixelates the whole image and not just part of it as illustrated in the example. I even used the same code as the example in two different servers (the second one had the latest version of IM installed). Not sure if this is a feature that is no longer working, or if it's not working just for me for some reason, but I'd greatly appreciate some insight or help:
Here is my code (same as in the example, but php on a webserver instead of the command line):
Code: Select all
<?php
exec ("convert zelda_tn.gif -scale 50% -scale 200% zelda_pixelate.gif
convert zelda_tn.gif -gamma 0 -fill white \
-draw 'circle 65,53 50,40' zelda_face_mask.gif
convert zelda_tn.gif zelda_pixelate.gif zelda_face_mask.gif \
-composite zelda_anonymity.png");
?>
Re: Partial Image Pixelation Not Working
Posted: 2010-11-21T23:13:41-07:00
by anthony
You probably need to include semi-colons between the commands in PHP.
It is also possible to do all the actions in a single command, probably with parenthesis. See Im examples basics. which will remove the need for intermediate images.
The only reason I break it into multiple commands in IM examples is to make the steps simpler and allow me to display those intermediate images.
See... Why do you use multiple "convert" commands
http://www.imagemagick.org/Usage/api/#multi-convert
Re: Partial Image Pixelation Not Working
Posted: 2010-11-21T23:40:14-07:00
by mynatome
Hi Anthony and thanks for the reply.
I used the longer version for illustration purposes, but I also have tried the shorter version that uses only one convert. I don't believe semicolons are needed in the example I provided in this thread with PHP since I'm using the exec command which does end in a semicolon.
The exec command is used to execute code from an external program (IM in this case), so ideally this should have worked. Instead I'm getting a 100% pixelated image. I'm not 100% sure though since I have little experience with IM. Anything else you think I should try?
Thanks for the great code and examples by the way!
Re: Partial Image Pixelation Not Working
Posted: 2010-11-22T00:07:09-07:00
by anthony
The next thing is where you are writing the images. Often the PHP code in a web server runs as a special user with little to no privileges.
Now you get one image, but that may have been to an existing file, or maybe even that file is not being updated and you just see the same file over and over. Check the file and directory permissions. check the dates on the file after a run. Remove the previous results after every run.
Is the intermediate 'mask' image correct? Can you redirect error messages to personal log file?
See
http://www.ict.griffith.edu.au/~anthony ... /php.hints
Later you will need to remember that code in a web server could be run by more than one client at the same time. Each run must use a different set of temporary files or you will get problems as the number of users start to cause simultaneous runs.
Re: Partial Image Pixelation Not Working
Posted: 2010-11-22T02:15:12-07:00
by mynatome
I checked my file permissions actually and the file access is set to 777 recursively for that directory, so I'm guessing it's not an access permissions issue.
I also set up the error log but nothing there either. Also, checked and the images are fresh every time. The mask image is being created and I can see that it's a transparent gif, but it's strange that the final image is still 100% pixelated.
Any other suggestions at this point? Thanks again for all your insight and help!
Re: Partial Image Pixelation Not Working
Posted: 2010-11-22T10:08:22-07:00
by mynatome
I was able to get this info about the current ImageMagick installed in my shared Media Temple web hosting account:
convert is /usr/bin/convert
locate: /var/cache/locate/locatedb: No such file or directory
Version: ImageMagick 6.2.4 09/16/06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2005 ImageMagick Studio LLC
Path: /usr/lib/ImageMagick-6.2.4/config/type-ghostscript.xml
Could the fact that it's an older version be an issue?
Re: Partial Image Pixelation Not Working
Posted: 2010-11-22T10:46:26-07:00
by Bonzo
This works for me:
Code: Select all
<?php
exec ("convert http://www.imagemagick.org/Usage/photos/zelda_tn.gif -scale 25% -scale 400% zelda_pixelate.gif ");
exec ("convert http://www.imagemagick.org/Usage/photos/zelda_tn.gif -gamma 0 -fill white -draw \"circle 65,53 50,40\" zelda_face_mask.gif ");
exec ("convert http://www.imagemagick.org/Usage/photos/zelda_tn.gif zelda_pixelate.gif zelda_face_mask.gif -composite zelda_anonymity.png ");
?>
I have never tried running three converts in one exec and it does not seem to work.
As Anthony said with use of parenthases and other mods you could probably get it all in one comand.
Re: Partial Image Pixelation Not Working
Posted: 2010-11-22T13:41:00-07:00
by mynatome
I finally got this to work, but only on another webserver. It never worked on the MediaTemple shared web hosting account I have, but it worked in another shared web hosting account with HostGator.com.
I suspect it may have to do with the ImageMagick version installed in MediaTemple or some other setting. In MediaTemple no matter what, it always pixelated the final image to 100%.
Bonzo thanks for your code, however I can get this to work with multiple converts the way I initially had the code, but I do see the benefit of separated the converts.
Thanks again to both Anthony and Bonzo for your input. I still would be interested if you may know why this did not work on the other server.
Re: Partial Image Pixelation Not Working
Posted: 2010-11-22T13:50:43-07:00
by Bonzo
It sounds as though it was compositing the images in the wrong order; try echoing each image and see what they look like.
Do you know how to display the version?
Code: Select all
<?php
echo "<pre>";
system("convert -version");
echo "</pre>";
?>
When I tried all 3 converts on one line I was just getting the black mask with the white circle as the final image although it was not created when I tried to view it as zelda_face_mask.gif!
Re: Partial Image Pixelation Not Working
Posted: 2010-11-22T14:04:52-07:00
by mynatome
Bonzo you are right, I think having the separate converts and right syntax within the PHP exec is important.
The version on the other server where this did not work is: 6.2.4
Thanks for the version code, it's similar to the one I used for the command line. For the webserver I used the following, but yours is simplier:
Code: Select all
<?php
header('Content-Type: text/plain');
system("exec 2>&1; pwd");
system("exec 2>&1; type convert");
system("exec 2>&1; locate */convert");
system("exec 2>&1; convert -version");
system("exec 2>&1; convert -list type"); //<!-- before IM v6.3.5-7 -->
system("exec 2>&1; convert -list font");
print("------ENVIRONMENT VARIABLES-------\n");
system("exec 2>&1; env");
?