php image resize on the fly help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    php image resize on the fly help

    Hi there.

    I need some help here with something...

    Has someone perhaps got some coding for a php thumbnail script?
    On the fly, meaning that you can resize images
    Example: image.php?imgdir=$whatever

    And it will resize the image to, lets say 640 x 480 or whatever, but still keep aspect ratio.
    I did play around with some coding, but cant seem to work around keeping the aspect ratio.

    Thank you in advance.
    Quintin

    #2
    found some old simple script that i have used long ago

    PHP Code:
    <?php
    if( is_array($_REQUEST) )
        {
            while( list(
    $k$v) = each($_REQUEST) )
            {
                if( 
    is_array($_REQUEST[$k]) )
                {
                    while( list(
    $k2$v2) = each($_REQUEST[$k]) )
                    {
                        $
    $k[$k2] = addslashes($v2);
                    }
                    @
    reset($_REQUEST[$k]);
                }
                else
                {
                    $
    $k addslashes($v);
                }
            }
            @
    reset($_REQUEST);
        }

    $size getimagesize($filename);
    if((
    $size['mime'] == 'image/gif'||$size['mime'] == 'image/jpeg'||$size['mime']=='image/png')&& !empty($filename))
    {
    if(
    $height>500)$height500;
    if(
    $width>500)$width500;
    if(!
    $height)$height128;
    if(!
    $width)$width128;

    header('Content-type: image/jpeg');

    $width_orig=$size[0];
    $height_orig=$size[1];

    if (
    $width && ($width_orig $height_orig)) {
       
    $width = ($height $height_orig) * $width_orig;
    } else {
       
    $height = ($width $width_orig) * $height_orig;
    }

    // Resample
    $image_p imagecreatetruecolor($width$height);
    if(
    $size['mime']=="image/gif")$image imagecreatefromgif($filename);
    if(
    $size['mime']=="image/jpeg")$image imagecreatefromjpeg($filename);
    if(
    $size['mime']=="image/png")$image imagecreatefrompng($filename);
    imagecopyresampled($image_p$image0000$width$height$width_orig$height_orig);

    // Output
    imagejpeg($image_pnull80);
    ImageDestroy ($image_p);
    }
    else
    {

    }
    ?>
    usage example : image.php?filename=image/dir/pic.jpg&width=300&height=300
    Advertise your mobile site for FREE with AdTwirl

    Comment


      #3
      thanks for your reply...

      I actually sat and worked around the problem i had. using a class upload script which does most of the work for me.

      Then I'm using another thumb.php script that i've done just to make pics a bit smaller for the wap version of the website i coded.

      Thanks a lot though.

      Quintin

      Comment

      Working...
      X