Tiling images with phMagick

August 9, 2009 by nuno costa 2 comments

phMagick :: tabstrips

It's easy to combine several images in one, creating a tabstrip with is useful for css roll-overs.

phMagick can create tabstrips from an array of path's or from phMagick image history, so you can perform several manipulations and use them as source for the tabstrip

From array

$paths = array(
 'darken70.png'
 ,'darken30.png'
 ,'resize_porp_wh.png'
 ,'brighten30.png'
 ,'brighten70.png'
 );
 
 $phMagick = &new phMagick();
 $phMagick->setDestination('tabstripArray.png')
 ->tabStrip($paths);

Result

From phMagick History

$phMagick = &new phMagick('lipe.png');
 $phMagick->setHistory('lipe.png') // adding original image to history
 ->restart() // all actions are applied to original image
 ->darken()
 ->restart() // all actions are applied to original image
 ->brighten()
 ->restart()
 ->invertColors()
 
 ->setDestination('tabstripHistory.png') //seting the tabstrip image name
 ->tabStrip() // create the tabstrip from phMagick history
 ->clear() // clears phMagick and deletes the files in history
 // in this case original file will also be deleted because we included it in history
 ;

Result

 

2 comments so far Add Your Comment

  1. by Pako on February 12 2010 at 23:00

    Hi Franco,
    first of all congratulations for your great job!
    I’ve tried both examples without success. The errors I get are something like “bad call, tabStrip not exists” for the first one, and “bad call, restart not exists” for the second. I think you are in middle of a major reestrucuration of your source and probably that’s the cause, could you give-me some help to make these examples to work?
    Thank you

  2. by nuno costa on February 12 2010 at 23:42

    @Pako

    Yes, the code was refactored and tabStrip() was renamed to tile() but the example was not updated

    function tile ( Array $paths = null, $tileWidth = ”, $tileHeight = 1 )

    if you don’t specify $paths it will use phMagick history to determine which files to tile

    the main difference between tabStrip and tile is that tile can “glue” images vertically and horizontally, the default behavior is to tile them horizontally (like tabStrip)

    if you do tlie($paths, 3,3) it will create a 3×3 grid of images

    hope this help, let me know if you need further assistance

More from francodacosta.com

© francodacosta.com - All rights reserved