Current location: Hot Scripts Forums » Programming Languages » PHP » Rotate an image (CW, CCW) in php?


Rotate an image (CW, CCW) in php?

Reply
  #1 (permalink)  
Old 08-15-03, 03:12 AM
borgo borgo is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Rotate an image (CW, CCW) in php?

I recently started with image resizing using GD and I was wondering if image rotating is also possible.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-15-03, 04:19 AM
kickinhard007's Avatar
kickinhard007 kickinhard007 is offline
Newbie Coder
 
Join Date: Aug 2003
Location: Manchester, UK
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
can you explain a little more about the rotation? do you want it to rotate at certain times or on certain dates?

do you want some images to rotate move than others? etc etc
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-15-03, 04:38 AM
borgo borgo is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
This is not about banner rotation or anything similar. I'm talking about editing pictures, resizing, croping, rotating etc.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 08-15-03, 08:47 AM
kickinhard007's Avatar
kickinhard007 kickinhard007 is offline
Newbie Coder
 
Join Date: Aug 2003
Location: Manchester, UK
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
i'm not that familiar with GD, i would recommend that you do a google search for 'GD rotating images' or something similar.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 08-16-03, 04:47 AM
borgo borgo is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Allright, this is it...

PHP Code:

<?


    
//**************************************
    // Name: Image rotation using GD extension
    // Description:A function with the intention of rotating a Jpeg image 90° Clockwise, Counterclockwise and 180°(Flip).
    // By: Karl Blessing
    //
    //
    // Inputs:Source file ( path to the source )
    //Destination ( path to the destination, can be same as source if you want to overwrite )
    //degrees (integer value of 90(counterclockwise), 270(clockwise) or 180)
    //
    // Returns:does not return a value, will save the destination, no indication if successful is returned.
    //
    //Assumes:When writing this I found various behaviors between images with greater x than y's and so forth. Thus is why all the condiotionals. The function has not been tested for images with same x and y dimensions, and will not likely work. 
    //IMPORTANT:
    //You must have PHP 4.3.* or above for this function to work, a PHP version lower will not work. I was using PHP 4.3.2 for Win32, with GD Extension version 2 ( bundled with PHP ).
    //
    //Side Effects:None
    //This code is copyrighted and has limited warranties.
    //Please see [url]http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.1074/lngWId.8/qx/vb/scripts/ShowCode.htm[/url]
    //for details.
    //**************************************
    
    
function rotatePix($sourcefile$targetfile$degrees)
    {
        
$img_size getImageSize($sourcefile);
        
$x $img_size[0];
        
$y $img_size[1];
        if (
$x $y)
        {
            
$dst_x 0;
            
$dst_y $x $y;
            
$newd $x;
        }
        else
        {
            
$dst_x $y $x;
            
$dst_y 0;
            
$newd $y;
        }
        
$src_img ImageCreateFromJPEG($sourcefile);
        
$dst_img ImageCreateTrueColor($newd,$newd);
        
        if (((
$x y) && ($degrees 180)) || (($y $x) && ($degrees 180)))
            
ImageCopyResampled($dst_img,$src_img,0,0,0,0,$x,$y,$x,$y);
        else
            
ImageCopyResampled($dst_img,$src_img,$dst_x,$dst_y,0,0,$x,$y,$x,$y);
        
        
$rotated_img ImageRotate($dst_img$degrees,0);
        
        if (
$degrees != 180)
        {
            
//90 CounterClockWise or Clockwise
            
$final_img ImageCreateTrueColor($y,$x);
            
ImageCopyResampled($final_img,$rotated_img,0,0,0,0,$y,$x,$y,$x);
        }
        else
        {
            
//180 Degrees
            
$final_img ImageCreateTrueColor($x,$y);
            
ImageCopyResampled($final_img,$rotated_img,0,0,0,0,$x,$y,$x,$y);
        }
        
ImageJPEG($final_img$targetfile);    
    }

        
rotatePix("foto.jpg""foto.jpg""270");

?>

Last edited by borgo; 08-16-03 at 04:50 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
PHP Dudes - Hi All stuart New Members & Introductions 4 05-03-04 02:22 PM
Custom PHP Scripts BdSBB Job Offers & Assistance 3 12-07-03 10:49 AM
PHP Triad/Upload form eddyvlad PHP 6 10-07-03 12:17 AM
PHP Live Support image change Jakenorton Script Requests 2 07-28-03 05:28 AM


All times are GMT -5. The time now is 10:18 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.