Partial Image Pixelation Not Working

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
mynatome

Partial Image Pixelation Not Working

Post 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");
?>	
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Partial Image Pixelation Not Working

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
mynatome

Re: Partial Image Pixelation Not Working

Post 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!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Partial Image Pixelation Not Working

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
mynatome

Re: Partial Image Pixelation Not Working

Post 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!
mynatome

Re: Partial Image Pixelation Not Working

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

Re: Partial Image Pixelation Not Working

Post 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.
mynatome

Re: Partial Image Pixelation Not Working

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

Re: Partial Image Pixelation Not Working

Post 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!
mynatome

Re: Partial Image Pixelation Not Working

Post 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");
?
Post Reply