dweb Posted December 15, 2012 Share Posted December 15, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/272025-creating-and-cropping-an-image/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.