Jump to content

an imagecopyresampled cropping challenge


susanBuck

Recommended Posts

Ive built a cropper in flash ... here's a screencast of it working in action :

 

http://www.screencast.com/users/susanBuck/folders/Jing/media/3ab9dde4-6b20-4e68-bf15-3559a86b8824

 

 

and below is a final still screenshot with all sorts of notes on it for the sake of this question.

imagecopyresampled.jpg

 

 

So the cropper works fine, but flash can't actually edit images, as we all know. So im going to use php gd on the server to do that. So what happens is the user uses the flash interface, and when they're done they click "done" and flash sends variables over to php (the origin of the cropper, the width, the height, what the final image should be, etc etc)... Php uses those variables and using imagecopyresampled, makes the real change on the image.

 

my problem is, I cant quite get the math right in my imagecopyresampled variables

 

$destinationX          = ?;
$destinationY          = ?;
$destinationWidth   = ?;
$destinationHeight  = ?;
$sourceX 		 = ?;
$sourceY 		 = ?;
$sourceWidth          = ?;
$sourceHeight         = ?;

imagecopyresampled($thumb, $source, $destinationX, $destinationY, $sourceX, $sourceY, $destinationWidth, $destinationHeight, $sourceWidth, $sourceHeight);

 

Anyone have a clear enough understanding of imagecopyresampled to figure this out?

Link to comment
Share on other sites

i dont understand your problem?

 

maybe try something like?

 

 


<?php
// The file
$filename = 'test.jpg';
$percent = 0.5;

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

// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;

// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Output
imagejpeg($image_p, null, 100);
?> 


Link to comment
Share on other sites

i understand how to use imagecopyresampled, and am not looking for all the generic code to do a resizing...

 

i guess the tricky part of what im doing is because not only am i taking a selection of an image, but im taking it and then shrinking it / enlarging it to match a predetermined size.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.