Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
GD LIB - problem with resulting image size
Old 11-28-2011, 09:53 AM GD LIB - problem with resulting image size
numbenator's Avatar
Webmaster Talker

Posts: 523
Location: London
Trades: 0
Hi everyone.
Im having al ittle difulty with the GD lib and wondered if some one could help me out.

I have two images. 1 a jpg and the other a transparent PNG

I wish to firstly, resize the jpg. ( which i am doing successfully ).
I then want to lay the jgp BEHIND the png which basically has a transparent box in the middle which will show the jgp behind.

Im having a problem which is i am lsoing the width and height of the png for some reason or somethime like is hapening.

Firstly , i resize my original image which results in a image size 360x268

Code:
$percent = 0.5;

list($width, $height) = getimagesize('meanddad.jpg');
$new_width = $width * $percent;
$new_height = $height * $percent;
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg('meanddad.jpg');

imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

imagejpeg($image_p, "underlay_image.jpg");
WORKS FINE and underlay_image.jpg is created.


THEN i try to place this image behind a png which is 504 x 405
I want to keep the resulting image and NOt crop or effect the png.

Code:
$width = 540;
$height = 405;
 
$bottom_image = imagecreatefromjpeg('underlay_image.jpg');
$top_image = imagecreatefrompng('Photo-Template.png');

imagesavealpha($top_image, false);      // enable transparancy
imagealphablending($top_image, false);

imagecopy($bottom_image, $top_image, 0, 0, 0, 0, $width, $height);

imagepng($bottom_image, "new_image.png");
The resulting image new_image.png is 360x268 NOT 504x405 and accrodingly, the front image ( the png ) is now cropped.

I am sure i have done something silly would would really aprepciate a pointer on this please.

Thanks
__________________

Please login or register to view this content. Registration is FREE

Last edited by numbenator; 11-28-2011 at 09:58 AM..
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
 
Register now for full access!
Old 11-28-2011, 01:44 PM Re: GD LIB - problem with resulting image size
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Well, you are copying a 504x405 image onto a 360x268 image, so it only seems naturl that the copied image would have to shrink. I don't know if it works, but you could try setting the coordinates negative, to shift the .png image so that its' center is placed on top of the .jpg image's center.

PHP Code:
imagecopy($bottom_image$top_image00, -72, -69$width$height); 
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 11-28-2011, 01:59 PM Re: GD LIB - problem with resulting image size
numbenator's Avatar
Webmaster Talker

Posts: 523
Location: London
Trades: 0
Thanks for your reply. I actually ended up sorting the problem creating a canvas for the background image of 540 x 405 and resizing on that.
Issue sorted but thanks for you input.
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Reply     « Reply to GD LIB - problem with resulting image size
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.32716 seconds with 12 queries