Connecting Tech Pros Worldwide Help | Site Map

Changing (jpg) Image size

  #1  
Old March 7th, 2006, 01:55 AM
Schraalhans Keukenmeester
Guest
 
Posts: n/a
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.
  #2  
Old March 7th, 2006, 03:25 AM
Schraalhans Keukenmeester
Guest
 
Posts: n/a

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.
  #3  
Old March 8th, 2006, 09:25 AM
Mitul
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB .Net "File in Use" on Loading JPG image into a picture box... Bill N. answers 2 November 22nd, 2005 03:09 PM
Image Quality problem somequestion answers 7 November 19th, 2005 11:31 PM
VB .Net "File in Use" on Loading JPG image into a picture box... Bill N. answers 2 July 21st, 2005 07:16 PM
changing image size on roll over Kenny answers 4 July 20th, 2005 01:30 PM