Page 1 of 1

using imagecopy from a resized image. Let me explain...

Posted: Fri Sep 10, 2010 2:28 am
by mupparion
Hi,

I have the following code

Code: Select all

$w=$_GET['w'];
$h=isset($_GET['h'])?$_GET['h']:$w;
$x=isset($_GET['x'])?$_GET['x']:0;
$y=isset($_GET['y'])?$_GET['y']:0;
$filename=$_GET['src'];
header('Content-type: image/jpg');
header('Content-Disposition: attachment; filename='.$src);
$image = imagecreatefromjpeg($filename); 
$crop = imagecreatetruecolor($w,$h);
imagecopy ( $crop, $image, 0, 0, $x, $y, $w, $h );
imagejpeg($crop);
And display it as such

Code: Select all

<img src="crop.php?x=<?php echo $_GET['x1']; ?>&y=<?php echo $_GET['y1']; ?>&w=300&h=300&src=cropper/castle.jpg">
So say the image is 500 x 333, it crops out a 300x300 section of it from X and Y. Works fine.
BUT, when i resize the image to say 450 x 300, it obviously still crops it from the 500 x 333 version so it looks different to what it should do.
I need a way to be able to resize the image in the above PHP and then imagecopy from that.

Cant think of how that would be done, any ideas?

Thank you!

Re: using imagecopy from a resized image. Let me explain...

Posted: Fri Sep 10, 2010 3:37 am
by requinix
mupparion wrote:BUT, when i resize the image to say 450 x 300, it obviously still crops it from the 500 x 333 version so it looks different to what it should do.
What? The example you gave will crop cropper/castle.jpg. If you resize that particular image and save it right back to that particular filename then the code will crop the resized version. If you don't save it to that particular filename then of course it'll use the old image - so long as you keep putting that name in the URL.

Re: using imagecopy from a resized image. Let me explain...

Posted: Fri Sep 10, 2010 4:02 am
by mupparion
Well i was kinda hoping there was some height/width variables i could pass through to some of the functions in my php and do it that way.
But i've just created a script now to resize the image and save it out with a different name and use that.

Thanks for you help :)