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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mupparion
Forum Newbie
Posts: 15
Joined: Tue Sep 22, 2009 3:48 am

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

Post 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!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
mupparion
Forum Newbie
Posts: 15
Joined: Tue Sep 22, 2009 3:48 am

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

Post 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 :)
Post Reply