Jump to content

Image Cropping


Cruisecar

Recommended Posts

I've been making a roulette script that basicly spins the image in PHP (a roulette wheel), it's working fine except sometimes the image becomes bigger than I want it, the actuall roulette wheel remains the same size.

 

It's obviously because the corners of the image are now extending over the borders, so PHP then compensates for this and fills in the rest of the background.

 

(I hope i'm making sense so far).

 

I want the image to either not be extended over 269x269 in the first place, or to be cropped after rotation. Can anybody help me do this? Here is a sample of the current rotation code. It all goes wrong on the imagecopyresampled() part.

 

  $original = "../images/wheel.jpg";

  $original = imagecreatefromjpeg($original);

      $angle = $angles[$num];

      $bgColour = 0x2F2F2F;

      $rotated = imagerotate($original, $angle, $bgColour);

 

  $cwd = getcwd();

      $tempfile = tempnam("$cwd/tmp", "temp_image_");

      $temphandle = fopen($tempfile, "w");

      fwrite($temphandle, $rotated);

      fclose($temphandle);

      list($width, $height) = getimagesize($tempfile);

 

 

// imagecopyresampled($rotated, $rotated, 0, 0, 0, 0, "269", "269", $width, $height);

 

imagejpeg($rotated);

    unlink($tempfile);

 

I hope someone can help me!

 

Thankyou

Link to comment
https://forums.phpfreaks.com/topic/41348-image-cropping/
Share on other sites

      $cwd = getcwd();

      $tempfile = tempnam("$cwd/tmp", "temp_image_");

      $temphandle = fopen($tempfile, "w");

      fwrite($temphandle, $rotated);

      fclose($temphandle);

      list($width, $height) = getimagesize($tempfile);

 

The $width and $height variables don't seem to contain any values, is there any easier way to get the image size?

Link to comment
https://forums.phpfreaks.com/topic/41348-image-cropping/#findComment-200370
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.