Image upload size in version 3

Hi, is there a way to set image resampling in 3.5.7?
I have a client who is unable to upload images to her blog. I have suggested that she resized them but this is all well and good for those of us familiar with image editors but she cant understand why she cannot just use what she has?
I know there are settings in v4 for this, but where are they in the classic version?
Thanks

I suspect you could add the required GD image resizing code quite easily to Pulse’s upload-img.php file. There is an example script here that should get you started.

Rather than sizing the images at upload I’ve tended to size them at use in the past using mThumb. The script will size and cache the image as it is called by the template so you can use the same image at various sizes throughout your site just by passing different sizes to the script. I recall adding this to a site I did where the client uploaded a huge image to use in a home page slider which completely blew the layout apart and took ages to load.

Adjusting the images on upload will save you some server space if the client uploads huge images whereas using mThumb offers you a few more options especially if you want to use the image at different sizes.

Thanks very much Tim. Resizing at upload is the way I want to go. I might play with the GD script but looking at it I suspect that deploying that is above my paygrade! I know how easily entire sites can stop working because of a mistake in a php script.
If you or anyone could suggest which bits to paste in that would be brilliant.
Cheers
James

edit: just noticed that there is a timthumb folder already inside pulsepro/plugins so I guess the functionality is built in somewhere. Just dont know how to deploy it.

Yes Pulse v3 used TimThumb which is how I came to find mThumb as it offers a lot of the same functionality but without the security issues. You should try and replace TimThumb for mThumb in Pulse if you can. I think the script was used to build thumbnails for the gallery pages in the CMS.

If I get a chance I’ll take a look at upload-img.php and see if I can adjust things to resize the images for you.

After a little digging in Pulse 3.5.7 I see that the CMS uses Plupload to upload images into the galleries. If you look in pulse pro > includes > choose-img.php you’ll hopefully see that Pulse should already be trying to resize the images for you in the lines;

// Resize images on clientside if we can
resize : {width : 1000, height : 1000, quality : 90},

Check to see if the resulting images on the server are already sized to 1000 pixels. If they aren’t then I’ll take another look at the GD script I’d mentioned previously.

So if the image resizing in choose-img.php doesn’t work for you then you can edit the upload-img.php file directly to do the image sizing for you there.

Open the file up and look for the line that starts;

if(move_uploaded_file($_FILES[“file”][“tmp_name”],
“…/data/img/gallery/”. $gallery ."/". $fileName))
chmod("…/data/img/gallery/". $gallery ."/". $fileName,0777);

and add in the following code after this block;

// Resize the image on the server
// start

$maxDim = 800; //800px high or wide
$uploadedfile = “…/data/img/gallery/”. $gallery ."/". $fileName;
$src = imagecreatefromjpeg($uploadedfile);
list($width, $height) = getimagesize($uploadedfile);

$path_parts = pathinfo($uploadedfile);
$ext = $path_parts[‘extension’];

//is the file a JPG
//is the largest side of the image longer than the size we want to scale the image to?
//ie Don’t scale the images up!
if ( (max($width,$height) > $maxDim) && ($ext == “jpg”) ){

//is the image landscape, portrait or square?
if ($width > $height){
$ratio = $height / $width;
$outputwidth = $maxDim;
$outputheight = $maxDim * $ratio;
}

if ($width < $height){
$ratio = $width / $height;
$outputheight = $maxDim;
$outputwidth = $maxDim * $ratio;
}

if ($width === $height){
$outputheight = $maxDim;
$outputwidth = $maxDim;
}

$tmp = imagecreatetruecolor($outputwidth, $outputheight);
$filename = “…/data/img/gallery/” . $gallery ."/". $fileName;
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $outputwidth, $outputheight, $width, $height);
imagejpeg($tmp, $filename, 80); // set the JPG quality here
imagedestroy($tmp);
}

// Resize the image on the server
// end

The $maxDim variable holds the maximum JPG width or height so set this to whatever you feel works for your client. You may also want to have a play with the JPG image quality setting (currently set to 80) at the bottom of the script until you’ve a happy trade off of of file size and image quality.

I’m sure I’ll regret doing the image ratio calculations like this as I’m sure there is a better way but it should work even if it is a little verbose. :slight_smile:

1 Like

Tim you are an absolute star - thank you so much, its really appreciated.
I’ll have a go at that later.
All best
James

2 Likes

This topic was automatically closed after 3 hours. New replies are no longer allowed.