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
Need insights on using GD. Some flaky stuff going on
Old 09-30-2008, 12:06 AM Need insights on using GD. Some flaky stuff going on
Experienced Talker

Posts: 38
Name: Alan
Trades: 0
I am generating a website and my customer needs to puload multiple photos of each product.

I am using GD functions to make two copies of the photos. One a 640 x480 for a slide show and one 160 x 120 thumbnail for use on another page of the site.

The upload and the generation of the 640 x 480 version works great every time.

Generating the thumbnail works with most of the photos though sometimes refuses to work for some photos. If I upload 6 photos, 4 or 5 of them will be just fine but one or two MAY not work. For example:

product_1.jpg - works great
product_2.jpg - works great
product_3.jpg - works great
product_4.jpg - No thumbnail generated
product_5.jpg - works great
product_6.jpg - works great

In the above example, the photo named "product_4.jpg" did not work in the thumbnail generation but all others worked great. Changing the order of upload has no effect and "product_4.jpg" always fails the thumbnail generation. There is no real difference in file sizes so I can't see a problem there.

Any insight on what may be happening? I don't want to deliver a product that has random issues like this. Is there some other method besides imagecopyresized() I should use?

I don't have imagemajick on the web server at all and my hosting is ATT (used to be Yahoo).
__________________

Please login or register to view this content. Registration is FREE
alhefner is offline
Reply With Quote
View Public Profile Visit alhefner's homepage!
 
 
Register now for full access!
Old 09-30-2008, 01:58 AM Re: Need insights on using GD. Some flaky stuff going on
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Do not use GD to resize images, use imagemagick's convert utility.
__________________

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

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 09-30-2008, 01:59 AM Re: Need insights on using GD. Some flaky stuff going on
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
If you do not have imagemagick on your host and there is no opportunity to install it there I strongly recommend you to change your hoster.
__________________

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

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-01-2008, 12:20 AM Re: Need insights on using GD. Some flaky stuff going on
Experienced Talker

Posts: 38
Name: Alan
Trades: 0
I think I solved, or worked around, the problem. It's all in the math! My original code:
PHP Code:
 function createthumb($name,$filename,$max_w,$max_h){
        
$src_img=imagecreatefromjpeg("../images/".$name);

    
$width=imageSX($src_img);
    
$heigth=imageSY($src_img);

    
$x_ratio$max_w $width;
    
$y_ratio$max_h $heigth;

    if ((
$width <= $max_w) && ($heigth <= $max_h)){
        
$tn_width $width;
        
$tn_heigth $heigth;
    }
    else{
        
$tn_width ceil($x_ratio $width);
        
$tn_heigth $max_h;
    }

    
$dst_image ImageCreateTrueColor($tn_width,$tn_heigth);
        
imagecopyresampled($dst_image,$src_img,0,0,0,0,$tn_width,$tn_heigth,$width,$heigth);
    
imagejpeg($dst_image,$filename,100);
    
imagedestroy($src_img);
    
imagedestroy($dst_image);

This set the max heigth at a solid number no matter what the original image was. A simple change so to use the ratio for resize seems to have fixed it.
PHP Code:
$tn_heigth ceil($y_ratio $heigth); 
I had simply done a paste of a snippet to do this and now see that the original was flawed just slightly and that caused major confusion on my part.
__________________

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

Last edited by alhefner; 10-01-2008 at 12:21 AM.. Reason: typo
alhefner is offline
Reply With Quote
View Public Profile Visit alhefner's homepage!
 
Reply     « Reply to Need insights on using GD. Some flaky stuff going on
 

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.13791 seconds with 12 queries