Results 1 to 3 of 3

Thread: Batc picture resize

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    16

    Batc picture resize

    How Can i resize a batch picture in Php Is their any command .If so Then Kindly tell me

    thanks in advance

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Batc picture resize

    You can use imagecopyresized if you have GD installed. If you are using ImageMagick, use ResampleImage or one of its variants.

  3. #3
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Batc picture resize

    Remember to take into consideration, if you are using this for image upload and you are allowing multiple formats, that you need to use different imagecreatefrom____()

    EDIT:

    here is a script i used for image resizing. Note that this doesn't save the image. it is for resizing on the flash

    PHP Code:
    <?php
    session_start
    ();
    $mem_id $_SESSION['member_id'];
    # Constants
    define(IMAGE_BASE'../pics/');
    define(IMAGE_BASE1'../pics/');
    define(MAX_WIDTH90);
    define(MAX_HEIGHT90);

    # Get image location
    $image_file str_replace('..'''$_SERVER['QUERY_STRING']);
    $image_path IMAGE_BASE.$image_file;
    //print $image_path;

    # Load image
    $img null;
    $ext strtolower(end(explode('.'$image_path)));
    if (
    $ext == 'jpg' || $ext == 'jpeg') {
        
    $img = @imagecreatefromjpeg($image_path);
    } else if (
    $ext == 'png') {
        
    $img = @imagecreatefrompng($image_path);
    # Only if your version of GD includes GIF support
    }
    else if (
    $ext == 'gif') {
        
    $img = @imagecreatefromgif($image_path);
    # Only if your version of GD includes GIF support
    }
    else if (
    $ext == 'bmp') {
        
    $img imagecreatefrombmp($image_path);
    # Only if your version of GD includes GIF support
    }
    else if (
    $ext == 'tif') {
        
    $img imagecreatefromtif($image_path);
    # Only if your version of GD includes GIF support
    }

    # If an image was successfully loaded, test the image for size
    if ($img) {

        
    # Get image size and scale ratio
        
    $width imagesx($img);
        
    $height imagesy($img);
        
    $scale min(MAX_WIDTH/$widthMAX_HEIGHT/$height);

        
    # If the image is larger than the max shrink it
        
    if ($scale 1) {
            
    $new_width floor($scale*$width);
            
    $new_height floor($scale*$height);

            
    # Create a new temporary image
            
    $tmp_img imagecreatetruecolor($new_width$new_height);

            
    # Copy and resize old image into new image
            
    imagecopyresampled($tmp_img$img0000,
                             
    $new_width$new_height$width$height);
            
    imagedestroy($img);
            
    $img $tmp_img;
        }
    }

    # Create error image if necessary
    if (!$img) {
    # Get image location
    $image_file str_replace('..'''$_SERVER['QUERY_STRING']);
    $image_path IMAGE_BASE1."nophoto.jpg";

    # Load image
    $img null;
    $ext strtolower(end(explode('.'$image_path)));
    if (
    $ext == 'jpg' || $ext == 'jpeg') {
        
    $img = @imagecreatefromjpeg($image_path);
    } else if (
    $ext == 'png') {
        
    $img = @imagecreatefrompng($image_path);
    # Only if your version of GD includes GIF support
    }

    # If an image was successfully loaded, test the image for size
    if ($img) {

        
    # Get image size and scale ratio
        
    $width imagesx($img);
        
    $height imagesy($img);
        
    $scale min(MAX_WIDTH/$widthMAX_HEIGHT/$height);

        
    # If the image is larger than the max shrink it
        
    if ($scale 1) {
            
    $new_width floor($scale*$width);
            
    $new_height floor($scale*$height);

            
    # Create a new temporary image
            
    $tmp_img imagecreatetruecolor($new_width$new_height);

            
    # Copy and resize old image into new image
            
    imagecopyresampled($tmp_img$img0000,
                             
    $new_width$new_height$width$height);
            
    imagedestroy($img);
            
    $img $tmp_img;
        }
    }
    }

    # Display the image
    if($img)
    {
    header("Content-type: image/jpeg");
    imagejpeg($img);
    }
    else
    {
    print 
    "$image_path";
    }
    ?>
    My usual boring signature: Something

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width