"Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid." – Albert Einstein

Rotate Image



How to rotate Image using PHP
Rotate PNG images…
function LoadPNG($imgname)
{
$im = @imagecreatefrompng($imgname); /* Attempt to open */
if (!$im) { /* See if it failed */
$im = imagecreatetruecolor(150, 30); /* Create a blank image */
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring($im, 1, 5, 5, “Error loading $imgname”, $tc);
}
return $im;
}
header(“Content-Type:image/png”);
$img = LoadPNG(“images/html_f2.png”);

// File and rotation
$degrees = 270;

// Rotate
$rotate = imagerotate($img, $degrees, 0);

// Output
//echo “Original Image: ” . . ”
“;
imagejpeg($rotate);

Rotate JPG Image…
// File and rotation
$filename = ‘images/abt_01.jpg’;
$degrees = 90;

// Content type
header(‘Content-type: image/jpeg’);

// Load
$source = imagecreatefromjpeg($filename);

// Rotate
$rotate = imagerotate($source, $degrees, 0);

// Output
imagejpeg($rotate);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s