Coppermine Gallery | Resize uploaded Images

crazywolf2010
crazywolf2010 used Ask the Experts™
on
Hi,
I have more than 10GB of images uploaded at Coppermine Gallery.

Lots of these images are in resolution of 2048 X 1024 and size in excess of 5MB for each image. I wish to resize them to 640X480 so viewing doesn't chew up so much of bandwidth.

How can I do this using coppermine admin interface?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016

Commented:
I can't help with the Coppermine Admin part of things, but I can show you a PHP script that can be used to resize image files.  If you have PHP skills it will be easy to handle.  Please post back if you're interested in that approach.  Best, ~Ray

Author

Commented:
Hi Ray,
Many Thanks for your response.

I don't have great php skills but I know someone in my organization working on front end portal who can help me here. Please details me what needs to be done.

Will php script actually resize images or just change the size/crop image while displaying?

Thanks
Most Valuable Expert 2011
Top Expert 2016
Commented:
Here is a teaching example script that shows how to resize and crop images.  This is not an "entry-level" assignment in PHP, so you will want to have a seasoned professional working the integration issues.  PHP functions like imagejpeg() can either write the image to the browser or store the new image in the file system.  You will experience better overall performance if your process resizes the images once and stores the new images.
<?php // RAY_image_resize_and_crop.php
error_reporting(E_ALL);


// RESIZE AN IMAGE PROPORTIONALLY AND CROP TO THE CENTER


function resize_and_crop($original_image_url, $thumb_image_url, $thumb_w, $thumb_h, $quality=75)
{
    // ACQUIRE THE ORIGINAL IMAGE: http://us3.php.net/manual/en/function.imagecreatefromjpeg.php
    $original = imagecreatefromjpeg($original_image_url);
    if (!$original) return FALSE;

    // GET ORIGINAL IMAGE DIMENSIONS
    list($original_w, $original_h) = getimagesize($original_image_url);

    // RESIZE IMAGE AND PRESERVE PROPORTIONS
    $thumb_w_resize = $thumb_w;
    $thumb_h_resize = $thumb_h;
    if ($original_w > $original_h)
    {
        $thumb_h_ratio  = $thumb_h / $original_h;
        $thumb_w_resize = (int)round($original_w * $thumb_h_ratio);
    }
    else
    {
        $thumb_w_ratio  = $thumb_w / $original_w;
        $thumb_h_resize = (int)round($original_h * $thumb_w_ratio);
    }
    if ($thumb_w_resize < $thumb_w)
    {
        $thumb_h_ratio  = $thumb_w / $thumb_w_resize;
        $thumb_h_resize = (int)round($thumb_h * $thumb_h_ratio);
        $thumb_w_resize = $thumb_w;
    }

    // CREATE THE PROPORTIONAL IMAGE RESOURCE
    $thumb = imagecreatetruecolor($thumb_w_resize, $thumb_h_resize);
    if (!imagecopyresampled($thumb, $original, 0,0,0,0, $thumb_w_resize, $thumb_h_resize, $original_w, $original_h)) return FALSE;

    // ACTIVATE THIS TO STORE THE INTERMEDIATE IMAGE
    // imagejpeg($thumb, 'RAY_temp_' . $thumb_w_resize . 'x' . $thumb_h_resize . '.jpg', 100);

    // CREATE THE CENTERED CROPPED IMAGE TO THE SPECIFIED DIMENSIONS
    $final = imagecreatetruecolor($thumb_w, $thumb_h);

    $thumb_w_offset = 0;
    $thumb_h_offset = 0;
    if ($thumb_w < $thumb_w_resize)
    {
        $thumb_w_offset = (int)round(($thumb_w_resize - $thumb_w) / 2);
    }
    else
    {
        $thumb_h_offset = (int)round(($thumb_h_resize - $thumb_h) / 2);
    }

    if (!imagecopy($final, $thumb, 0,0, $thumb_w_offset, $thumb_h_offset, $thumb_w_resize, $thumb_h_resize)) return FALSE;

    // STORE THE FINAL IMAGE - WILL OVERWRITE $thumb_image_url
    if (!imagejpeg($final, $thumb_image_url, $quality)) return FALSE;
    return TRUE;
}


// USE CASE
echo '<a target="_blank" href="RAY_orig_600x374.jpg">Original 600x374</a><br/>';

resize_and_crop('RAY_orig_600x374.jpg', 'RAY_temp_100x100.jpg', 100, 100);
echo '<a target="_blank" href="RAY_temp_100x100.jpg">100x100</a><br/>';

resize_and_crop('RAY_orig_600x374.jpg', 'RAY_temp_200x100.jpg', 200, 100);
echo '<a target="_blank" href="RAY_temp_200x100.jpg">200x100</a><br/>';

resize_and_crop('RAY_orig_600x374.jpg', 'RAY_temp_200x300.jpg', 200, 300);
echo '<a target="_blank" href="RAY_temp_200x300.jpg">200x300</a><br/>';

Open in new window

HTH, ~Ray

Author

Commented:
Hi ray,
I got my friend to write a small fuction to resize & save files. So far it seem working OK . It does need bit of a tweaking.

Many Thanks mate.

Thanks
Most Valuable Expert 2011
Top Expert 2016

Commented:
Thanks for the points and best of luck with it, ~Ray

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial