Jump to content

Creating And Cropping An Image


dweb

Recommended Posts

Hi

 

I really could do with someone's help, i've tried a ton of things and nothing seems to work.

 

I have a HTML page which contains a 200px by 500px div

 

Behind that div, I have an image, which can be dragged around, resized and i've put a rotate tool in too.

 

Once the user is happy, they click a button and using javascript I store the following in the database

 

Width = the new width

Height = the new height

Left = how far left the image was dragged (ie: -100)

Top = how far from the top the image was dragged (ie: 20)

Angle = the rotation in degrees

Image = url of image (ie: ../images/photos/abcd.jpg)

 

The "top" and "left" can be positive values (ie: 300) or negative values (ie: -100)

 

I have stored those values as vars (ie: $var_rotate_value), what I want to do, is using GD library, replicate what the user did and save a copy of the image that was positioned inside the div, cropping everything around the outside of the div

 

I've tried so many things and nothing is working for me

 

It either shows the wrong size, or it doesn't rotate correctly, or the position is way off

 

I have attached an image to try and show you what im trying to do

 

The code i'm using and hacking around is;

 

$filename = '../images/photos/abcd.jpg';
$nfile = $var_photo_url_value;

$degrees = $var_rotate_value;

$source = imagecreatefromjpeg($filename);
$rotate = imagerotate($source, $degrees, 0);
imagejpeg($rotate, $nfile, 100);
imagedestroy($rotate);

$div_area_width = 200;
$div_area_height = 500;

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

$from_left = $var_left_value;
$from_top = $var_top_value;

$new_width = $var_width_value;
$new_height = $var_height_value;
$image_p = imagecreatetruecolor($div_area_width, $div_area_height);
$image = imagecreatefromjpeg($nfile);

imagecopyresampled($image_p, $image, 0, 0, $from_left, $from_top, $new_width, $new_height, $width, $height);
imagejpeg($image_p, $nfile, 100);
imagedestroy($image_p);

 

Can someone help please?

 

ta

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.