Results 1 to 10 of 10

Thread: image rotation

  1. #1
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default image rotation

    hello, i want to take an image, rotate it 15 degrees then center it in a white canvas 220 width x 120 height.


    thanks

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    This sounds like it would be done with JavaScript, not PHP.

    Edit: Seems I was wrong, sort of forgot about the GD library =/
    Last edited by Schmoopy; 09-19-2009 at 12:05 AM.

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

  4. #4
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,419
    Thanks
    103
    Thanked 117 Times in 115 Posts

    Default

    You can use php for this. I do.

    http://us2.php.net/manual/en/function.imagerotate.php
    and
    http://us2.php.net/manual/en/functio...ecopymerge.php

    should do it. For the list of GD functions that php uses go to http://us2.php.net/manual/en/book.image.php . Here is an amateur tutorial that I created on the subject. http://www.animeviews.com/article.ph...ry=programming
    To choose the lesser of two evils is still to choose evil. My personal site

  5. #5
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Or PHP-GD.

    PHP Code:
    <?php

    $filename 
    'test.jpg';

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

    $source imagecreatefromjpeg($filename);
    $rotate imagerotate($source150);

    $im imagecreate(220120);
    $img imagecopy($im$im000000);

    imagejpeg($rotate);
    ?>
    I think I REALLY screwed that up, but that's the outline for you. HTH
    - Josh

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The GD library for PHP will rotate it and give you an image. Flash will let you do it on the page. Javascript won't be much help because it won't do well with non-90-degree angles (if you wanted to make an image sideways, there is probably a reasonably way in Javascript, but not 15 degrees).
    Based on what you said, I think the GD library as suggested above is the right way to go.

    However, it's probably better to just save these images in the first place as you want, using a PHP-GD script if you'd like, but not running it every time the page loads, because that will be slow and cause a strain on the server. If you are doing it with user uploads or something else you can't batch process before, then you could just process once with GD and save that output so you are still only running the script once.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Sounds like he has a unique image every time, so I think he'll have no choice but to run the script each time. Maybe he can make a copy of the image if the image is repeated?
    - Josh

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Right. If it can't be pregenerated, then caching the image is the best option.

    I have a gallery script I did where it is live-- it just grabs all the images from the folder and puts them on the page (as thumbnails generated by GD, with links to the actual files), but it does so by looking through all the images in the folder and generating the thumbnail only if the thumbnail is not already saved in a folder. I save the thumbnail based on the md5 value of the image itself, so that is an easy way to be sure the image hasn't been updated. The only downside to that is leaving extra thumbnails in the cached folder once an image is deleted, but it doesn't really cause much of a problem.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    thanks guys,

    i'm just having a play with a few of the scripts..

    If you look at the images i've attached, you can clearly see what im after..

    thanks for your help

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    In addition to the image you want, exactly, you need to also decide how you want it to work-- process the image every time the page loads, preprocess everything, do it only if it isn't already generated, etc. For this, the reasons behind the script are most important-- is it part of your layout, for products on a page, for user uploaded photos, etc.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •