Connecting Tech Pros Worldwide Help | Site Map

Changing (jpg) Image size

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 7th, 2006, 12:55 AM
Schraalhans Keukenmeester
Guest
 
Posts: n/a
Default Changing (jpg) Image size

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, 02:25 AM
Schraalhans Keukenmeester
Guest
 
Posts: n/a
Default 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, 08:25 AM
Mitul
Guest
 
Posts: n/a
Default 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;
}

 

Bookmarks

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.