Connecting Tech Pros Worldwide Forums | Help | Site Map

Changing (jpg) Image size

Schraalhans Keukenmeester
Guest
 
Posts: n/a
#1: Mar 7 '06
I am looking for a way to resize uploaded (jpg) images automatically.
My ISP hasn't got any preinstalled image manipulation library installed
on the (centos) serverhost, so I either have to come up with something
in PHP, Perl, Java or some other (CGI) applet/application.

GD is installed and active, but I can't find any suitable function so far.

Preferrably I stick to PHP, but if it isn't possible I would opt for any
of the alternatives.

Any good tips, pointers, links?
Thanks!
Sh.

Schraalhans Keukenmeester
Guest
 
Posts: n/a
#2: Mar 7 '06

re: Changing (jpg) Image size


Schraalhans Keukenmeester wrote:[color=blue]
> I am looking for a way to resize uploaded (jpg) images automatically.
> My ISP hasn't got any preinstalled image manipulation library installed
> on the (centos) serverhost, so I either have to come up with something
> in PHP, Perl, Java or some other (CGI) applet/application.
>
> GD is installed and active, but I can't find any suitable function so far.
>
> Preferrably I stick to PHP, but if it isn't possible I would opt for any
> of the alternatives.
>
> Any good tips, pointers, links?
> Thanks!
> Sh.[/color]
Whoops, sorry, found the imagecreatefrom and imagecopyresized functions.
My bad. Simply missed those on first reading the imagefunction chapters.

Rgds
Sh.
Mitul
Guest
 
Posts: n/a
#3: Mar 8 '06

re: Changing (jpg) Image size


Hello Schraalhans,

Please use following function which was developed by me you can use it
directly.

If u have any problem Please contact me on mitul[at]siliconinfo[dot]com

function thumbgenerator($forcedwidth, $forcedheight, $sourcefile,
$destfile, $imgcomp)
{
$g_imgcomp=100-$imgcomp;
$g_srcfile=$sourcefile;
$g_dstfile=$destfile;
$g_fw=$forcedwidth;
$g_fh=$forcedheight;
if(file_exists($g_srcfile))
{
$g_is=getimagesize($g_srcfile);
if(($g_is[0]-$g_fw)>=($g_is[1]-$g_fh))
{
$g_iw=$g_fw;
$g_ih=($g_fw/$g_is[0])*$g_is[1];
}
else
{
$g_ih=$g_fh;
$g_iw=($g_ih/$g_is[1])*$g_is[0];
}
$src=explode(".",$g_srcfile);
$var=count($src);
if($src[$var-1]=='gif' || $src[$var-1]=='GIF')
{
$img_src=ImageCreateFromGIF($g_srcfile);
//$img_src= ImageColorAllocate($img_src, 250, 250, 250);
$img_dst=imagecreate($g_iw,$g_ih);
$img_dst1 = ImageColorAllocate($img_dst, 255, 255, 255);
}
if($src[$var-1]=='png')
{
$img_src=ImageCreateFromPNG($g_srcfile);
$img_dst=imagecreate($g_iw,$g_ih);
$img_dst1 = ImageColorAllocate($img_dst,255, 255, 255);
}
if($src[$var-1]=='jpg' || $src[$var-1]=='JPG')
{
$img_src=imagecreatefromjpeg($g_srcfile);
$img_dst=imagecreate($g_iw,$g_ih);
$img_dst = &imageCreateTrueColor( $g_iw, $g_ih);
}

imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih,
$g_is[0], $g_is[1]);
if($src[$var-1]=='jpg' || $src[$var-1]=='JPG')
{
imagejpeg($img_dst, $g_dstfile, $g_imgcomp);
}
if($src[$var-1]=='png')
{
imagepng($img_dst, $g_dstfile, $g_imgcomp);
}
if($src[$var-1]='gif' || $src[$var-1]=='GIF')
{
imagegif($img_dst, $g_dstfile, $g_imgcomp);
}
imagedestroy($img_dst);
return true;
}
else
return false;
}

Closed Thread