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.

Fonts Installed view - Anthony 15/6/2008

This shows all the installed fonts with the name written using the actual font. There were acouple of problems with this example. 1/ The ' had been missed out in the preg_match and 2/ I have found that the array generated with font and type are different. I tested it with a version below 6.3.5 and it worked but would not work in versions above that. I have modifeid the code to work with both versions but it will need to be tidied up.

  1. <?php 
  2. system("convert -version");
  3. // Select the version number from the configeration file
  4.     preg_match('/^LIB_VERSION_NUMBER ([0-9,]+)$/m'shell_exec("convert -list configure "), $vnums);
  5. // Seperate the numbers at the ,
  6.     $number explode","$vnums[1] );
  7. // Format the version from 6,3,4,1 format to 06030401
  8.     $version "";
  9.     for($i=0;$i<4;$i++)
  10.     {
  11.     $version .= str_pad$number[$i], 2'0'STR_PAD_LEFT );
  12.     }    
  13.    
  14. // The 'list' method used to get the fonts changed in IM v6.3.5-7
  15.     $font_list = ( $version "06030507" ) ? "font" "type";
  16. // Populate the array only - do not display it
  17.     exec("convert -list $font_list"$IMarray$code);
  18.    
  19. // Sort the array alphabeticly
  20.     sort$IMarray );
  21. // Setup some default values
  22.     $delete = array();
  23.     $image_list "";
  24. // Function to remove items from array
  25.     function array_delete$array$filterfor ){ 
  26.         $thisarray = array (); 
  27.         foreach( $array as $value 
  28.         if( stristr$value$filterfor )===false && strlen$value )>0
  29.         $thisarray[] = $value
  30.         return $thisarray
  31.     } 
  32. // Remove items containing Name from the arrary
  33.     $NoName array_delete$IMarray"Name" ); 
  34. // Remove items containing Path: from the array
  35.     $NoPath array_delete$NoName"Path:" ); 
  36. // Remove items containing Path: from the array
  37.     $NoFamily array_delete$NoPath"family:" );
  38.    
  39. // Remove items containing Path: from the array
  40.     $NoStretch array_delete$NoFamily"stretch:" );
  41.    
  42.    // Remove items containing Path: from the array
  43.     $NoWeight array_delete$NoStretch"weight:" );
  44.    
  45.       // Remove items containing Path: from the array
  46.     $NoStyle array_delete$NoWeight"style:" );
  47.    
  48. // Find the amount of items in the array
  49.     $count count$NoStyle );
  50. // Reduce the count by one as the array starts at 0
  51.     $count $count-1;
  52. // Start the loop to generate the images
  53.     for ( $i=2$i<=$count$i++ ) {
  54. // Get the font name from the array
  55.         $FirstPart explode(':'$NoStyle[$i]);
  56.         $Font str_replace' '''$FirstPart['1']);   
  57.         $Image $Font.".png";   
  58.       
  59. // Create the images
  60. $cmd "-size 250x15 xc:lightblue -font $Font -pointsize 13 -draw \"gravity West fill black text 0,0 $Font \" ";
  61. // echo $cmd."<br>";
  62. exec("convert $cmd $Image");
  63. // Generate the list of images for use in the large image
  64.         $image_list $image_list." ".$Image;
  65. // Generate the array of tempory images to delete
  66.         $delete[] = $Image;
  67.     }
  68. // Create the large image
  69.     exec("convert -background white -gravity Center $image_list -append fonts.png");
  70. // Delete the tempory images
  71.     foreach ( $delete as $value ) { 
  72.         unlink$value ); }
  73. ?> 
  74. <img src="fonts.png">

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