dweb Posted March 15, 2013 Share Posted March 15, 2013 (edited) Hi I have a website that has a jQuery image dragger script, which lets you move an image up and down a fixed 500x800 area, the code ends up looking like; <div style="width:500px; height:800px; overflow:hidden"><div style="position: relative; top: -200px"><img width="500" src="images/test_image.jpg"></div></div> This all works ok, and what i'm doing is then saving the css "top" value in my database. In the example above, i'm saving -200 in the database. I'm saving it because i might want to go back and adjust the image position later on So my problem is, when I come to processing the image, I want to use imagecopy(); to crop the image to the positioned sized but when I pass my -200 value from the database imagecopy(images/NEW_image.jpg, images/test_image.jpg, 0, 0, 0, -200, 500, 800); it seems to crop the wrong way how can I get PHP to correct that value so it crops correctly? thanks Edited March 15, 2013 by dweb Quote Link to comment https://forums.phpfreaks.com/topic/275695-imagecopy-question/ Share on other sites More sharing options...
jazzman1 Posted March 15, 2013 Share Posted March 15, 2013 Where is your php script? Also, what data type has this field in database when you try to save the negative value? Quote Link to comment https://forums.phpfreaks.com/topic/275695-imagecopy-question/#findComment-1418863 Share on other sites More sharing options...
dweb Posted March 15, 2013 Author Share Posted March 15, 2013 (edited) Hi Jazzman1 The type is int(5) and the record saves as "-200" My PHP image processing code looks like; $position = $rowdata['image_position']; $src = imagecreatefromjpeg('images/saved_photo.jpg'); $dest = imagecreatetruecolor(500, 800); imagecopy($dest, $src, 0, 0, 0, $position, 500, 800); imagejpeg($dest,'images/copped_photo.jpg'); imagedestroy($dest); imagedestroy($src); The value $rowdata['image_position'] is the css top position that was saved (ie: -200) thanks Edited March 15, 2013 by dweb Quote Link to comment https://forums.phpfreaks.com/topic/275695-imagecopy-question/#findComment-1418864 Share on other sites More sharing options...
jazzman1 Posted March 15, 2013 Share Posted March 15, 2013 Did you save the file to the right destination or not? Quote Link to comment https://forums.phpfreaks.com/topic/275695-imagecopy-question/#findComment-1418865 Share on other sites More sharing options...
dweb Posted March 15, 2013 Author Share Posted March 15, 2013 Yes, it all works fine, it's just that it -200 crops in the wrong direction Quote Link to comment https://forums.phpfreaks.com/topic/275695-imagecopy-question/#findComment-1418874 Share on other sites More sharing options...
jazzman1 Posted March 15, 2013 Share Posted March 15, 2013 I've never use the imagecopy php function, but if you try to change -200 to +200, what's happening? Do not remove the plus symbol. Quote Link to comment https://forums.phpfreaks.com/topic/275695-imagecopy-question/#findComment-1418875 Share on other sites More sharing options...
kicken Posted March 16, 2013 Share Posted March 16, 2013 Having a negative crop setting doesn't make sense to me. Your crop rectangle should be within the bounds of the original image's size. The top should be between 0 and the original height, and the left should be between 0 and the original width. If I am mis-understanding what it is you are attempting to do, you'll need to explain better, possibly with a visual aid. Quote Link to comment https://forums.phpfreaks.com/topic/275695-imagecopy-question/#findComment-1418970 Share on other sites More sharing options...
jazzman1 Posted March 16, 2013 Share Posted March 16, 2013 (edited) I've made a simple test with a negative y-coordinate of source point value setting it to -200, and it works just fine. Here it is: <?php // Create image instances $src = imagecreatefromjpeg('images/12 Giulio Berruti picture.2.jpg'); $dest = imagecreatetruecolor(500, 800); // Copy imagecopy($dest, $src, 0, 0, 0, -200, 500, 800); // Output the image header('Content-Type: image/jpeg'); imagejpeg($dest,NULL, 90); // free from memory imagedestroy($dest); imagedestroy($src); Edited March 16, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/275695-imagecopy-question/#findComment-1418980 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.