Share on Google+Share on Google+

PHP GD flip image

This example shows how to display and flip image in php gd.


$image = imagecreatefromjpeg("images.jpg");

$image = flip($image,1,1);

header("Content-type: image/jpeg");



function flip($i,$h=1,$v=0) {

$width = imagesx($i);

$height = imagesy($i);

$temp = imagecreatetruecolor($width,$height);


if ($h==1) {

for ($x=0 ; $x<$width ; $x++) {

imagecopy($i, $temp, $width-$x-1, 0, $x, 0, 1, $height);




if($v==1) {

for ($x=0; $x<$height ; $x++) {

imagecopy($i, $temp, 0, $height-$x-1, 0, $x, $width, 1);



return $i;



After running the program you will get the following output


Posted on: November 7, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.