Snippets - With php

Snippets index page

NOTE: Most of the IM snippets have been tested on IM version 6.3.5 There may be some differences if you are using the code on other versions.

Writing IM code - Anthony 15/6/2008

Below are some different ways you can write the IM code. I always used to use the exec( ); with everything on the same line and still do for short code. But with complicated code it makes it easyer to read if you use the $cmd version.

  1. <?php
  2. $color "red";
  3. $image "rose:";
  4. $size "70x46";
  5. $string "A Rose by any Name";
  6. // Example 1 - Using concatenate
  7. exec("convert -background none -fill $color -gravity center " .
  8.             " -font Candice -size $size caption:\"$string\" " .
  9.             " \\( $image -negate -flip \\) +swap -composite " .
  10.             " output.gif" );
  11. // Example 2 - Using the imagemagick line continuation of \    
  12. // You need to escape the \ with another \ so it becomes \\    
  13. exec("convert -background none -fill \'$color\' -gravity center \\
  14.         -font Candice -size $size caption:\"$string\" \\
  15.         \\( $image -negate -flip \\) +swap -composite \\
  16.         output.gif" );
  17. // Example 3 - Writing the comand into a variable        
  18. $cmd "-background none -fill $color -gravity center " .
  19.             " -font Candice -size $size caption:\"$string\" " .
  20.             " \( $image -negate -flip \) +swap -composite ";            
  21. exec("convert $cmd output.gif" );
  22. // Example 4 - One long line        
  23. exec("convert -background none -fill $color -gravity center -font Candice -size $size caption:\"$string\" \\( $image -negate -flip \\) +swap -composite output.gif" );
  24. ?>

For more examples and information check out the main Imagemagick section.

Batch file View

Check size before resizing View

Dividing an image View

Fonts Installed view View

Get image data into a variable 1 View

Get image data into a variable 2 View

Gravity option View

New image size in variable View

Row of images View

Setup Information View

Use an array View

Warhol effect View