Welcome to WebmasterWorld Guest from 54.242.63.214

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

alternative to "phpthumb"?

     

httpwebwitch

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

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month