Changing (jpg) Image size

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Schraalhans Keukenmeester

    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.
  • Schraalhans Keukenmeester

    #2
    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 imagecopyresize d functions.
    My bad. Simply missed those on first reading the imagefunction chapters.

    Rgds
    Sh.

    Comment

    • Mitul

      #3
      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=$sou rcefile;
      $g_dstfile=$des tfile;
      $g_fw=$forcedwi dth;
      $g_fh=$forcedhe ight;
      if(file_exists( $g_srcfile))
      {
      $g_is=getimages ize($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_srcfil e);
      $var=count($src );
      if($src[$var-1]=='gif' || $src[$var-1]=='GIF')
      {
      $img_src=ImageC reateFromGIF($g _srcfile);
      //$img_src= ImageColorAlloc ate($img_src, 250, 250, 250);
      $img_dst=imagec reate($g_iw,$g_ ih);
      $img_dst1 = ImageColorAlloc ate($img_dst, 255, 255, 255);
      }
      if($src[$var-1]=='png')
      {
      $img_src=ImageC reateFromPNG($g _srcfile);
      $img_dst=imagec reate($g_iw,$g_ ih);
      $img_dst1 = ImageColorAlloc ate($img_dst,25 5, 255, 255);
      }
      if($src[$var-1]=='jpg' || $src[$var-1]=='JPG')
      {
      $img_src=imagec reatefromjpeg($ g_srcfile);
      $img_dst=imagec reate($g_iw,$g_ ih);
      $img_dst = &imageCreateTru eColor( $g_iw, $g_ih);
      }

      imagecopyresamp led($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_d st, $g_dstfile, $g_imgcomp);
      }
      if($src[$var-1]='gif' || $src[$var-1]=='GIF')
      {
      imagegif($img_d st, $g_dstfile, $g_imgcomp);
      }
      imagedestroy($i mg_dst);
      return true;
      }
      else
      return false;
      }

      Comment

      Working...