ImageRotate() Rotating Image by GD

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

$file_name='../images/top2.jpg'; // Image collected
$angle='180';    // Angle of rotation is set
$img_source = imagecreatefromjpeg($file_name); // Image created

$img_rotated = imagerotate($img_source, $angle, 0); // Rotate the image

imagejpeg($img_rotated); // Output Displayed

imagedestroy($img_source);  // Free the memory 
imagedestroy($img_rotated); // Free the memory
Above code is saved as gd-imagerotate-demo.php and displayed in this page, HTML code is here.
<img src=gd-imagerotate-demo.php>

$source_image : Image resource created before
$angle: Rotational angle in degree
$bg_color: Color of the uncovered zone after rotation
$int_transparent: Transparent colors are ignored if value is given and not 0

Using background colour

header ("Content-type: image/jpg");
$angle='45'; // Angle of rotation in degree
$img_source = imagecreatefromjpeg($file_name);
$bg_color = ImageColorAllocate ($img_source, 4, 20, 204);
// Rotate
$img_rotated = ImageRotate($img_source, $angle, $bg_color, 0);
// Output Display 
// Free the memory
Above code is saved as gd-imagerotate-demo2.php and displayed in this page, HTML code is here.
<img src=gd-imagerotate-demo2.php>

GD functions ImageString() to add text to Image
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer