How to resize an image with php

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

    How to resize an image with php

    Hello,

    I need to insert a resized image in a html page.

    I know that using the html IMG tag it is possible to set the height
    and width attributes, with no need of php (or server-side processing).

    But my problem is the following:
    I need to use the resized image as a table background - and
    unfortunately html doesn't support the resize function for image used
    as background !


    Is it possible to resize an image dinamically (on the fly) by using
    php ?
    Is it possible without having GD libraries installed ?

    Thanks in advance for your help.
    Giovanni.
  • Shawn Wilson

    #2
    Re: How to resize an image with php

    Giovanni wrote:[color=blue]
    >
    > I need to insert a resized image in a html page.
    >
    > I know that using the html IMG tag it is possible to set the height
    > and width attributes, with no need of php (or server-side processing).
    >
    > But my problem is the following:
    > I need to use the resized image as a table background - and
    > unfortunately html doesn't support the resize function for image used
    > as background !
    >
    > Is it possible to resize an image dinamically (on the fly) by using
    > php ?
    > Is it possible without having GD libraries installed ?[/color]

    You can do it dynamically with GD. PHP doesn't have any built-in image
    functions.

    If you have ImageMagick (ImageMagick.or g), you can use that too. And you may be
    able to use GIMP, but I'm not sure.

    Regards,
    Shawn
    --
    Shawn Wilson
    shawn@glassgian t.com

    Comment

    • CountScubula

      #3
      Re: How to resize an image with php

      > >[color=blue][color=green]
      > > Is it possible to resize an image dinamically (on the fly) by using
      > > php ?
      > > Is it possible without having GD libraries installed ?[/color]
      >[/color]



      Ok, the real quick and simple:

      use this:

      img src=pic.php?p=m e.jpg&w=100&h=1 0

      then here is the pic.php

      $p = $_GET['p'];
      $w = $_GET['w'];
      $h = $_GET['h'];

      $ims = imagecreatefrom jpeg("path_to_p ics/$p");
      $ow = imagesx($ims); $oh = imagesy($ims);
      $imd = imagecreate($w, $h);
      imagecopyresize d($imd,$ims,0,0 ,0,0,$w,$h,$ow, $oh);
      //imagecopyresamp led($imd,$ims,$ 0,$0,0,0,$w,$h, $ow,$oh);

      header("Content-type: image/jpeg");
      imagejpeg($imd) ;

      Thats it, its real quick and dirty, and it even lets you set a few
      paramers on the img src tag :)
      (use resampled instead of resized if compiled into your php, better
      algorithm)


      Mike Bradley
      http://gzen.myhq.info -- free online php tools

      Comment

      Working...