SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Kiwi Fr00t jylyn's Avatar
    Join Date
    Apr 2005
    Location
    New Zealand
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    GD imagerotate() not resizing image

    Hi

    I'm not sure whether I'm doing something wrong here or I've misunderstood the manual, but here is my problem...

    I'm using imagerotate() to -oddly enough- rotate an image:

    PHP Code:
    $img imageCreateTrueColor(200300);
    $red imageColorAllocate($img25500);

    $img imageRotate($img120$red0);
        
    header("Content-type: image/png");
    imagePNG($img);
    exit(); 
    Despite the stated dimensions of the image being 200x300, this script outputs a 360x324 image.

    The manual says:
    "The center of rotation is the center of the image, and the rotated image is scaled down so that the whole rotated image fits in the destination image - the edges are not clipped."

    Shouldn't this mean the image should stay at 200x300 as specified?

  2. #2
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not sure what could cause such behaviour, but you can use imagecopyresized() after rotation

  3. #3
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,397
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    Is it something to do with the $red in the code as that is linked to $img? Try putting the colour or variable containing just the colour instead of $red to see if it has any effect.

  4. #4
    Kiwi Fr00t jylyn's Avatar
    Join Date
    Apr 2005
    Location
    New Zealand
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the ideas. It's nothing to do with the red. Basically I started out with a rather complicated script involving all sorts of images and manipulations and gradually eliminated things I thought might be causing the problem. I got right down to the basics and still couldn't fix it...

  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    You are rotating the image to a value that is not 90 degrees (e.g. no flat sides). So the image must increase in size to accommodate the rotation.

    The manual says:
    "The center of rotation is the center of the image, and the rotated image is scaled down so that the whole rotated image fits in the destination image - the edges are not clipped."

    Shouldn't this mean the image should stay at 200x300 as specified?
    No it means it will increase in dimensions, if the edges were clipped then yes it would stay as 200x300.

    Might have better luck with a square image.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



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
  •