homepage Welcome to WebmasterWorld Guest from 54.235.39.132
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
alternative to "phpthumb"?
httpwebwitch




msg:3874825
 2:23 am on Mar 20, 2009 (gmt 0)

Hi

I'm currently using a PHP library called "phpthumb" which grabs images from a URL, creates thumbnails, and caches them locally for fast and permanent retrieval.

The problem is I've noticed it really isn't so fast. Indeed it's really quite slow.

Does anyone know of alternatives? Features I need are:

- user provides URL of a hosted image
- user also able to upload their own image (JPG, PNG, GIF)
- generate thumbnails with contrained proportions (in a set of standard sizes)
- copy of image cached locally on my server in case the hosted image goes away
- good error handling is important
- detect corrupt or unreadable images and replace with a default JPG

Any suggestions? I'd rather not have to build my own from scratch (though I will if I must)

 

httpwebwitch




msg:3882187
 5:36 am on Mar 31, 2009 (gmt 0)

never mind... I built one from scratch, custom suited to my needs.

to make this thread useful, I'll donate one of the functions that made it possible:
this one creates all the dimensions you need to fit an image inside he boundaries of a constrained thumbnail size. It returns an array of values you use

function fitinside($thumbsize,$srcw,$srch){
$proportion = $srcw/$srch;
$dstx = 0;
$dsty = 0;
$srcx = 0;
$srcy = 0;
$dstw = 0;
$dsth = 0;

if($srcw >= $srch){
// landscape or square
$dstx = 0;
$dsty = floor(($thumbsize/2) - (($thumbsize / $proportion)/2));
$dstw = $thumbsize;
$dsth = floor($thumbsize / $proportion);
}elseif($srcw < $srch){
//portrait
$dstx = floor(($thumbsize/2) - (($thumbsize * $proportion) / 2));
$dsty = 0;
$dstw = floor($thumbsize * $proportion);
$dsth = $thumbsize;
}

return array(
'dstx'=>$dstx,
'dsty'=>$dsty,
'srcx'=>$srcx,
'srcy'=>$srcy,
'dstw'=>$dstw,
'dsth'=>$dsth,
'srcw'=>$srcw,
'srch'=>$srch
);
}

you use it like this, passing the results to imagecopyresampled:

$srcw = [b]imagesx[/b]($originalimage);
$srch = [b]imagesy[/b]($originalimage);

$thumbsize = 40;
$thumbimage = [b]imagecreatetruecolor[/b]($thumbsize, $thumbsize);
$background = [b]imagecolorallocate[/b]($thumbimage, 255, 255, 255);
[b]imagefill[/b]($thumbimage,0,0,$background);
$f = [b]fitinside[/b]($thumbsize,$srcw,$srch);
[b]imagecopyresampled[/b]($thumbimage, $originalimage, $f['dstx'], $f['dsty'],$f['srcx'],$f['srcy'],$f['dstw'],$f['dsth'],$f['srcw'],$f['srch']);
[b]imagejpeg[/b]($thumbimage,"/images/".$imagename.".jpg",100);


coopster




msg:3882462
 2:59 pm on Mar 31, 2009 (gmt 0)

Thanks httpwebwitch.

Any suggestions? I'd rather not have to build my own from scratch (though I will if I must)

I wasn't aware of any other solutions therefore the lack of response. FWIW, this resize function is very close to how I handled it too. I custom rolled my own solution quite a few years ago and added it my image manipulation class.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved