Posted By

abhiomkar on 08/01/10


Tagged


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

ashloren
Vordreller
convergine
pytheas
bcmoney
Priestd09


PHP Code to generate thumbnails of all images in current directory


 / Published in: PHP
 

URL: http://www.randomsequence.com/articles/making-square-thumbnails-with-imagemagick/

  1. <?php
  2. $SQUARESIZE = 108; // the size in pixels for your square images
  3. $convertPath = "/usr/local/bin/convert"; // full path to ImageMagick's convert tool
  4.  
  5. $path = getcwd()."/"; // path to folder full of jpg files to convert
  6.  
  7. $n = 0;
  8.  
  9. if ($handle = opendir($path)) {
  10. while (false !== ($file = readdir($handle))) {
  11. if ($file != "." && $file != ".." && strpos($file,"jpg") !== false) {
  12. echo $file."\n";
  13. $originalname = $file;
  14.  
  15. $filenamePart = $n++;
  16.  
  17. $squarename = $filenamePart."_sq.jpg";
  18. $squareCommand = $convertPath." \"".$path.$originalname."\" -thumbnail x".($SQUARESIZE*2)." -resize '".($SQUARESIZE*2)."x&lt;' -resize 50% -gravity center -crop ".$SQUARESIZE."x".$SQUARESIZE."+0+0 +repage -format jpg -quality 91 \"".$path."sq/".$squarename."\"";
  19. system($squareCommand);
  20. }
  21. }
  22. closedir($handle);
  23. }
  24. ?>

Report this snippet  

You need to login to post a comment.