Quick Search for:  in language:    
function,with,intention,rotating,Jpeg,image,C
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
PHP Stats

 Code: 112,626. lines
 Jobs: 41. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login





Latest Code Ticker for PHP
Click here to see a screenshot of this code!A Simple FTP Solution
By Marcelo Valle Franco on 1/15

(Screen Shot)

Web Blog / Content Updater
By Matthew Sparrow on 1/14


Current Users Online v1
By Robert Peterson on 1/13


Click here to see a screenshot of this code!Blobsy : MSN Messenger Bot
By JawishHameed on 1/12

(Screen Shot)

Click here to see a screenshot of this code!Server-Side Browse for Image (with GUI)
By Tohir Solomons on 1/11

(Screen Shot)

Click here to see a screenshot of this code!Automatically Add a Watermark to an Image
By Patrick Krecker on 1/11

(Screen Shot)

Click here to see a screenshot of this code!RepleteSurveys
By Steve Schoenfeld on 1/7

(Screen Shot)

gameserver query
By tombuksens on 1/5


Random Password Generator
By Domenic Matesic on 1/3


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

Image rotation using GD extension

Print
Email
 
VB icon
Submitted on: 7/21/2003 4:04:06 AM
By: Karl Blessing 
Level: Beginner
User Rating: Unrated
Compatibility:PHP 4.0

Users have accessed this code 1187 times.
 

(About the author)
 
     A function with the intention of rotating a Jpeg image 90° Clockwise, Counterclockwise and 180°(Flip).
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    //**************************************
    //     
    // Name: Image rotation using GD extensi
    //     on
    // Description:A function with the inten
    //     tion of rotating a Jpeg image 90° Clockw
    //     ise, Counterclockwise and 180°(Flip).
    // By: Karl Blessing
    //
    // Inputs:Source file ( path to the sour
    //     ce )
    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 s
    //     uccessful is returned.
    //
    // Assumes:When writing this I found var
    //     ious behaviors between images with great
    //     er x than y's and so forth. Thus is why 
    //     all the condiotionals. The function has 
    //     not been tested for images with same x a
    //     nd y dimensions, and will not likely wor
    //     k. 
    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 ).
    //
    //This code is copyrighted and has    // limited warranties.Please see http://
    //     www.Planet-Source-Code.com/vb/scripts/Sh
    //     owCode.asp?txtCodeId=1074&lngWId;=8    //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);	
    }


Other 1 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
9/2/2003 1:40:50 PM:
To successfully use this code you 
must:
1)
call 
rotatePix(somewhere...)
2)
correct 
line #71 (or else you'll end up with 
halved images when rotating 90 or 270 
degrees...), from:
if ((($x > y) && 
($degrees < 180)) || (($y > $x) && 
($degrees > 180)))
with:
if ((($x > 
$y) && ($degrees < 180)) || (($y > $x) 
&& ($degrees > 180)))
Cheers, P.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | PHP Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.