crop an image

This is a discussion on crop an image within the PHP General forums, part of the PHP Programming Forums category; Hi there, I do have a small problem with the proportions of image copy The image is originally vertical in ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-31-2007
Merlin
 
Posts: n/a
Default crop an image

Hi there,

I do have a small problem with the proportions of image copy

The image is originally vertical in 100px width and 141px height.
Now I want to crop it to 80 px width and 60px height. There should be no
black area and the proportions should be OK. That means that I have to
copy only part of the image. In this case it would be 40.5px from above
(141-60 / 2 ) and until 100.5 (40.5+60).
This would crop the middle part of the image.

Now with imagecoyresampled I can set the starting point of 40.5px, but
not the ending point. The image will have a black bottom.

Here is the code I am using:
imagecopyresampled($outputImg, $inputImg, 0,0, 0 , 40.5, 80, 60, $srcX,
$srcY);

Thank you for any hint. Maybe somebody has a good idea on how to crop
that image.

Best regards,

Merlin
Reply With Quote
  #2 (permalink)  
Old 10-31-2007
David Christopher Zentgraf
 
Posts: n/a
Default Re: [PHP] crop an image

Copying half a pixel? I dare say that's where the problem is.

Chrs,
Dav

On 31 Oct 2007, at 19:34, Merlin wrote:

> Hi there,
>
> I do have a small problem with the proportions of image copy
>
> The image is originally vertical in 100px width and 141px height.
> Now I want to crop it to 80 px width and 60px height. There should
> be no black area and the proportions should be OK. That means that I
> have to copy only part of the image. In this case it would be 40.5px
> from above (141-60 / 2 ) and until 100.5 (40.5+60).
> This would crop the middle part of the image.
>
> Now with imagecoyresampled I can set the starting point of 40.5px,
> but not the ending point. The image will have a black bottom.
>
> Here is the code I am using:
> imagecopyresampled($outputImg, $inputImg, 0,0, 0 , 40.5, 80, 60,
> $srcX, $srcY);
>
> Thank you for any hint. Maybe somebody has a good idea on how to
> crop that image.
>
> Best regards,
>
> Merlin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Reply With Quote
  #3 (permalink)  
Old 10-31-2007
Merlin
 
Posts: n/a
Default Re: [PHP] crop an image

David Christopher Zentgraf schrieb:
> Copying half a pixel? I dare say that's where the problem is.
>
> Chrs,
> Dav
>
> On 31 Oct 2007, at 19:34, Merlin wrote:
>
>> Hi there,
>>
>> I do have a small problem with the proportions of image copy
>>
>> The image is originally vertical in 100px width and 141px height.
>> Now I want to crop it to 80 px width and 60px height. There should be
>> no black area and the proportions should be OK. That means that I have
>> to copy only part of the image. In this case it would be 40.5px from
>> above (141-60 / 2 ) and until 100.5 (40.5+60).
>> This would crop the middle part of the image.
>>
>> Now with imagecoyresampled I can set the starting point of 40.5px, but
>> not the ending point. The image will have a black bottom.
>>
>> Here is the code I am using:
>> imagecopyresampled($outputImg, $inputImg, 0,0, 0 , 40.5, 80, 60,
>> $srcX, $srcY);
>>
>> Thank you for any hint. Maybe somebody has a good idea on how to crop
>> that image.
>>
>> Best regards,
>>
>> Merlin
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>


got it, wrong command.
This is the right one:
imagecopy($outputImg, $inputImg, 0, 0, 0, $cropY, $srcX, $srcY);
Reply With Quote
  #4 (permalink)  
Old 10-31-2007
Merlin
 
Posts: n/a
Default Re: [PHP] crop an image

Hi everybody,

I am still strugling with the crop problem.

It looks like it is not possible with PHP to do an imagecopyresampled
and and imagecopy on the same image.

Here is what I try to do:
1: Resize image to 80px width and correct ratio
2: Crop from that image a 80x60 part

Both work for themselfes, but not together.

Does anybody see the problem?

$outputImg = ImageCreateTrueColor($maxX, $dstY);
imagecopyresampled($outputImg, $inputImg, $posX, $posY,0,0, $picX,
$picY, $srcX, $srcY);
$outputImg = ImageCreateTrueColor(80, 60);
imagecopy($outputImg, $inputImg, 0,0 , 0, 250, $picX, $picY);

If I leave the second imagecreate away, the image will be copied into
the bigger size and is not 80x60.

Thank you for any help.

Merlin

David Christopher Zentgraf schrieb:
> Copying half a pixel? I dare say that's where the problem is.
>
> Chrs,
> Dav
>
> On 31 Oct 2007, at 19:34, Merlin wrote:
>
>> Hi there,
>>
>> I do have a small problem with the proportions of image copy
>>
>> The image is originally vertical in 100px width and 141px height.
>> Now I want to crop it to 80 px width and 60px height. There should be
>> no black area and the proportions should be OK. That means that I have
>> to copy only part of the image. In this case it would be 40.5px from
>> above (141-60 / 2 ) and until 100.5 (40.5+60).
>> This would crop the middle part of the image.
>>
>> Now with imagecoyresampled I can set the starting point of 40.5px, but
>> not the ending point. The image will have a black bottom.
>>
>> Here is the code I am using:
>> imagecopyresampled($outputImg, $inputImg, 0,0, 0 , 40.5, 80, 60,
>> $srcX, $srcY);
>>
>> Thank you for any hint. Maybe somebody has a good idea on how to crop
>> that image.
>>
>> Best regards,
>>
>> Merlin
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>

Reply With Quote
  #5 (permalink)  
Old 10-31-2007
Merlin
 
Posts: n/a
Default Re: [PHP] crop an image

Merlin schrieb:
> Hi everybody,
>
> I am still strugling with the crop problem.
>
> It looks like it is not possible with PHP to do an imagecopyresampled
> and and imagecopy on the same image.
>
> Here is what I try to do:
> 1: Resize image to 80px width and correct ratio
> 2: Crop from that image a 80x60 part
>
> Both work for themselfes, but not together.
>
> Does anybody see the problem?
>
> $outputImg = ImageCreateTrueColor($maxX, $dstY);
> imagecopyresampled($outputImg, $inputImg, $posX, $posY,0,0, $picX,
> $picY, $srcX, $srcY);
> $outputImg = ImageCreateTrueColor(80, 60);
> imagecopy($outputImg, $inputImg, 0,0 , 0, 250, $picX, $picY);
>
> If I leave the second imagecreate away, the image will be copied into
> the bigger size and is not 80x60.
>
> Thank you for any help.
>
> Merlin
>
> David Christopher Zentgraf schrieb:
>> Copying half a pixel? I dare say that's where the problem is.
>>
>> Chrs,
>> Dav
>>
>> On 31 Oct 2007, at 19:34, Merlin wrote:
>>
>>> Hi there,
>>>
>>> I do have a small problem with the proportions of image copy
>>>
>>> The image is originally vertical in 100px width and 141px height.
>>> Now I want to crop it to 80 px width and 60px height. There should be
>>> no black area and the proportions should be OK. That means that I
>>> have to copy only part of the image. In this case it would be 40.5px
>>> from above (141-60 / 2 ) and until 100.5 (40.5+60).
>>> This would crop the middle part of the image.
>>>
>>> Now with imagecoyresampled I can set the starting point of 40.5px,
>>> but not the ending point. The image will have a black bottom.
>>>
>>> Here is the code I am using:
>>> imagecopyresampled($outputImg, $inputImg, 0,0, 0 , 40.5, 80, 60,
>>> $srcX, $srcY);
>>>
>>> Thank you for any hint. Maybe somebody has a good idea on how to crop
>>> that image.
>>>
>>> Best regards,
>>>
>>> Merlin
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>

got it, sorrry for the confusion. I mixed up the lables.
Reply With Quote
  #6 (permalink)  
Old 11-02-2007
Chris Bruce
 
Posts: n/a
Default Re: [PHP] crop an image

What was the solution here? I am trying to crop but am getting a
black bar the same height as the crop at top. For this image I want
to crop 40 pixels off of the top:

$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($jpegpath);
imagecopyresampled($image_p, $image, 0, 0, 0, 40, 765, 810, 665, 1000)
imagejpeg($image_p, $destImage, 75);

How do I merely crop x pixels from an image without having black
bars? I have tried the x coordinate too with the same result.

Thanks,

Chris

On Oct 31, 2007, at 8:58 AM, Merlin wrote:

> Merlin schrieb:
>> Hi everybody,
>> I am still strugling with the crop problem.
>> It looks like it is not possible with PHP to do an imagecopyresampled
>> and and imagecopy on the same image.
>> Here is what I try to do:
>> 1: Resize image to 80px width and correct ratio
>> 2: Crop from that image a 80x60 part
>> Both work for themselfes, but not together.
>> Does anybody see the problem?
>> $outputImg = ImageCreateTrueColor($maxX, $dstY);
>> imagecopyresampled($outputImg, $inputImg, $posX, $posY,0,0, $picX,
>> $picY, $srcX, $srcY);
>> $outputImg = ImageCreateTrueColor(80, 60);
>> imagecopy($outputImg, $inputImg, 0,0 , 0, 250, $picX, $picY); If
>> I leave the second imagecreate away, the image will be copied into
>> the bigger size and is not 80x60.
>> Thank you for any help.
>> Merlin
>> David Christopher Zentgraf schrieb:
>>> Copying half a pixel? I dare say that's where the problem is.
>>>
>>> Chrs,
>>> Dav
>>>
>>> On 31 Oct 2007, at 19:34, Merlin wrote:
>>>
>>>> Hi there,
>>>>
>>>> I do have a small problem with the proportions of image copy
>>>>
>>>> The image is originally vertical in 100px width and 141px height.
>>>> Now I want to crop it to 80 px width and 60px height. There
>>>> should be no black area and the proportions should be OK. That
>>>> means that I have to copy only part of the image. In this case
>>>> it would be 40.5px from above (141-60 / 2 ) and until 100.5 (40.5
>>>> +60).
>>>> This would crop the middle part of the image.
>>>>
>>>> Now with imagecoyresampled I can set the starting point of
>>>> 40.5px, but not the ending point. The image will have a black
>>>> bottom.
>>>>
>>>> Here is the code I am using:
>>>> imagecopyresampled($outputImg, $inputImg, 0,0, 0 , 40.5, 80, 60,
>>>> $srcX, $srcY);
>>>>
>>>> Thank you for any hint. Maybe somebody has a good idea on how to
>>>> crop that image.
>>>>
>>>> Best regards,
>>>>
>>>> Merlin
>>>>
>>>> --
>>>> PHP General Mailing List (http://www.php.net/)
>>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>

> got it, sorrry for the confusion. I mixed up the lables.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

Reply With Quote
  #7 (permalink)  
Old 11-06-2007
Chris Bruce
 
Posts: n/a
Default Re: [PHP] crop an image

Does anyone have some insight here? I am trying to crop an image. The
crop seems to almost work, but I get black bars on the image. Has
anyone had any experience with cropping images using the GD library?

Thanks.

Chris

On Nov 2, 2007, at 5:41 PM, Chris Bruce wrote:

> What was the solution here? I am trying to crop but am getting a
> black bar the same height as the crop at top. For this image I want
> to crop 40 pixels off of the top:
>
> $image_p = imagecreatetruecolor($width, $height);
> $image = imagecreatefromjpeg($jpegpath);
> imagecopyresampled($image_p, $image, 0, 0, 0, 40, 765, 810, 665, 1000)
> imagejpeg($image_p, $destImage, 75);
>
> How do I merely crop x pixels from an image without having black
> bars? I have tried the x coordinate too with the same result.
>
> Thanks,
>
> Chris
>
> On Oct 31, 2007, at 8:58 AM, Merlin wrote:
>
>> Merlin schrieb:
>>> Hi everybody,
>>> I am still strugling with the crop problem.
>>> It looks like it is not possible with PHP to do an
>>> imagecopyresampled
>>> and and imagecopy on the same image.
>>> Here is what I try to do:
>>> 1: Resize image to 80px width and correct ratio
>>> 2: Crop from that image a 80x60 part
>>> Both work for themselfes, but not together.
>>> Does anybody see the problem?
>>> $outputImg = ImageCreateTrueColor($maxX, $dstY);
>>> imagecopyresampled($outputImg, $inputImg, $posX, $posY,0,0,
>>> $picX, $picY, $srcX, $srcY);
>>> $outputImg = ImageCreateTrueColor(80, 60);
>>> imagecopy($outputImg, $inputImg, 0,0 , 0, 250, $picX, $picY);
>>> If I leave the second imagecreate away, the image will be copied
>>> into the bigger size and is not 80x60.
>>> Thank you for any help.
>>> Merlin
>>> David Christopher Zentgraf schrieb:
>>>> Copying half a pixel? I dare say that's where the problem is.
>>>>
>>>> Chrs,
>>>> Dav
>>>>
>>>> On 31 Oct 2007, at 19:34, Merlin wrote:
>>>>
>>>>> Hi there,
>>>>>
>>>>> I do have a small problem with the proportions of image copy
>>>>>
>>>>> The image is originally vertical in 100px width and 141px height.
>>>>> Now I want to crop it to 80 px width and 60px height. There
>>>>> should be no black area and the proportions should be OK. That
>>>>> means that I have to copy only part of the image. In this case
>>>>> it would be 40.5px from above (141-60 / 2 ) and until 100.5
>>>>> (40.5+60).
>>>>> This would crop the middle part of the image.
>>>>>
>>>>> Now with imagecoyresampled I can set the starting point of
>>>>> 40.5px, but not the ending point. The image will have a black
>>>>> bottom.
>>>>>
>>>>> Here is the code I am using:
>>>>> imagecopyresampled($outputImg, $inputImg, 0,0, 0 , 40.5, 80,
>>>>> 60, $srcX, $srcY);
>>>>>
>>>>> Thank you for any hint. Maybe somebody has a good idea on how
>>>>> to crop that image.
>>>>>
>>>>> Best regards,
>>>>>
>>>>> Merlin
>>>>>
>>>>> --
>>>>> PHP General Mailing List (http://www.php.net/)
>>>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>>

>> got it, sorrry for the confusion. I mixed up the lables.
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php

>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

Reply With Quote
  #8 (permalink)  
Old 11-06-2007
Edward Vermillion
 
Posts: n/a
Default Re: [PHP] crop an image


On Nov 6, 2007, at 10:20 AM, Chris Bruce wrote:

> Does anyone have some insight here? I am trying to crop an image.
> The crop seems to almost work, but I get black bars on the image.
> Has anyone had any experience with cropping images using the GD
> library?
>
> Thanks.
>
> Chris
>
> On Nov 2, 2007, at 5:41 PM, Chris Bruce wrote:
>
>> What was the solution here? I am trying to crop but am getting a
>> black bar the same height as the crop at top. For this image I
>> want to crop 40 pixels off of the top:
>>
>> $image_p = imagecreatetruecolor($width, $height);
>> $image = imagecreatefromjpeg($jpegpath);
>> imagecopyresampled($image_p, $image, 0, 0, 0, 40, 765, 810, 665,
>> 1000)


try imagecopyresampled($image_p, $image, 0, 0, 0, 0, 765, 810, 665,
1000)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:58 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0