Jump to content

Recommended Posts

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 by dweb
Link to comment
https://forums.phpfreaks.com/topic/275695-imagecopy-question/
Share on other sites

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 by dweb
Link to comment
https://forums.phpfreaks.com/topic/275695-imagecopy-question/#findComment-1418864
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/275695-imagecopy-question/#findComment-1418970
Share on other sites

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 by jazzman1
Link to comment
https://forums.phpfreaks.com/topic/275695-imagecopy-question/#findComment-1418980
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.