I'm quite new to Coppermine and was using Gallery until I found this wonderful image gallery.
However, I wanted to be able to resize my originals, well, actually for my sister who loves to take pictures.
I searched all over the forums and came to the conclusion (as I don't have Windows XP and don't use XP Publish) that I would have to make the changes myself.
I also noticed that other people were looking for something like this, so this is what I came up with, hope some of you can use it!
What it is
----------
This is a hack that allows you and your users to resize your original images during upload or after batch upload or in admin if you images are already uploaded.
How to Use
----------
- when Max width or height for uploaded pictures/videos (pixels) field is set under Files and thumbnails settings in your config
- applying the mod to upload.php allows you and your users to upload any dimension of image within the file size limits and resizes it to the Max width or height for uploaded pictures/videos (pixels) setting instead of not allowing the picture to be uploaded
- applying the mod to util.php allows you, as admin to resize your original pics within the Admin Tools under Update thumbs and/or resized photos or original photos (1) as the last option and, again uses the Max width or height for uploaded pictures/videos (pixels) field as the size to resample the image
The following files will need to be changed
-------------------------------------------
(path to your Coppermine install)/lang/english.php
(path to your Coppermine install)/upload.php
(path to your Coppermine install)/util.php
First make the language file changes...
---------------------------------------
english.php
find
'what_rebuild' => 'Rebuilds thumbnails and resized photos',
and replace with
'what_rebuild' => 'Rebuilds thumbnails, resized photos and original photos',
find
'thumbs_wait' => 'Updating thumbnails and/or resized images, please wait...',
'thumbs_continue_wait' => 'Continuing to update thumbnails and/or resized images...',
and replace with
'thumbs_wait' => 'Updating thumbnails and/or resized/original images, please wait...',
'thumbs_continue_wait' => 'Continuing to update thumbnails and/or resized/original images...',
find
'update' => 'Update thumbs and/or resized photos',
and replace with
'update' => 'Update thumbs and/or resized photos or original photos',
insert the following
'update_originals' => 'Resize original photos to max width/height for uploads as set in config.',
make the same changes to english-utf-8.php and/or any other language files you might be using...
upload.php file changes
-----------------------
Around line 1242 find
@unlink($path_to_image);
// The file upload has failed -- the image dimensions exceed the allowed amount.
$file_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'file_name'=> $file_name, 'error_code'=>$lang_upload_php['pixel_allowance']);
// There is no need for further tests or action, so skip the remainder of the iteration.
continue;
and replace with
// *** START *** Original Resize Mod ***
// Create a temporary copy of the image
$path_to_temp_image = './albums/edit/'. "temp_" . $prefix . $seed . '.' . $suffix;
if (rename($path_to_image, $path_to_temp_image) &&
copy($path_to_temp_image, $path_to_image) &&
resize_image($path_to_temp_image, $path_to_image, $CONFIG['max_upl_width_height'], $CONFIG['thumb_method'], $CONFIG['thumb_use']) &&
unlink($path_to_temp_image)) {
// Successfully resized the large image!
} else { // We had a failure, so go ahead and delete the image
@unlink($path_to_image);
// The file upload has failed -- the image dimensions exceed the allowed amount.
$file_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'file_name'=> $file_name, 'error_code'=>$lang_upload_php['pixel_allowance']);
// There is no need for further tests or action, so skip the remainder of the iteration.
continue;
}
// *** END *** Original Resize Mod ***
Around line 1914 find
@unlink($path_to_image);
// The file upload has failed -- the image dimensions exceed the allowed amount.
$URI_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'URI_name'=> $_POST['URI_array'][$counter], 'error_code'=>$lang_upload_php['pixel_allowance']);
// There is no need for further tests or action, so skip the remainder of the iteration.
continue;
and replace with
// *** START *** Original Resize Mod ***
// Create a temporary copy of the image
$path_to_temp_image = './albums/edit/'. "temp_" . $prefix . $seed . '.' . $suffix;
if (rename($path_to_image, $path_to_temp_image) &&
copy($path_to_temp_image, $path_to_image) &&
resize_image($path_to_temp_image, $path_to_image, $CONFIG['max_upl_width_height'], $CONFIG['thumb_method'], $CONFIG['thumb_use']) &&
unlink($path_to_temp_image)) {
// Successfully resized the large image!
} else { // We had a failure, so go ahead and delete the image
@unlink($path_to_image);
// The file upload has failed -- the image dimensions exceed the allowed amount.
$URI_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'URI_name'=> $_POST['URI_array'][$counter], 'error_code'=>$lang_upload_php['pixel_allowance']);
// There is no need for further tests or action, so skip the remainder of the iteration.
continue;
}
// *** END *** Original Resize Mod ***
util.php file changes
---------------------
Around line 187, insert the following
// *** START *** Original Resize Mod ***
if ($updatetype == 3) {
$original = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");
$temp_original = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . "temp_" . mysql_result($result, $i, "filename");
$imagesize = getimagesize($image);
if (max($imagesize[0], $imagesize[1]) > $CONFIG['max_upl_width_height']) {
if (rename($original, $temp_original) &&
copy($temp_original, $original) &&
unlink($temp_original) &&
resize_image($image, $original, $CONFIG['max_upl_width_height'], $CONFIG['thumb_method'], $CONFIG['thumb_use'])) {
// need to save new size of original to database!
$imagesize = getimagesize($original);
$pid = mysql_result($result, $i, "pid");
$update = "pwidth = " . (int) $imagesize[0];
$update .= ", pheight = " . (int) $imagesize[1];
$update .= ", filesize = " . (int) filesize($original);
$query = "UPDATE {$CONFIG['TABLE_PICTURES']} SET $update WHERE pid='$pid' LIMIT 1";
$result_resize = db_query($query);
print $original .' '. $lang_util_php['updated_succesfully'] . '!<br />';
my_flush();
} else {
print $lang_util_php['error_create'] . ':$original<br />';
my_flush();
}
}
}
// *** END *** Original Resize Mod ***
then around line 392, find the following
<input type="radio" name="updatetype" value="0" id="thumb" class="nobg" /><label for="thumb" accesskey="t" class="labelradio">' . $lang_util_php['update_thumb'] . '</label><br />
<input type="radio" name="updatetype" value="1" id="resized" class="nobg" /><label for="resized" accesskey="r" class="labelradio">' . $lang_util_php['update_pic'] . '</label><br />
<input type="radio" name="updatetype" value="2" checked="checked" id="all" class="nobg" /><label for="all" accesskey="a" class="labelradio">' . $lang_util_php['update_both'] . '</label><br />
and replace with
// *** START *** Original Resize Mod ***
<input type="radio" name="updatetype" value="0" id="thumb" class="nobg" /><label for="thumb" accesskey="t" class="labelradio">' . $lang_util_php['update_thumb'] . '</label><br />
<input type="radio" name="updatetype" value="1" id="resize_normal" class="nobg" /><label for="resize_normal" accesskey="r" class="labelradio">' . $lang_util_php['update_pic'] . '</label><br />
<input type="radio" name="updatetype" value="2" checked="checked" id="all" class="nobg" /><label for="all" accesskey="a" class="labelradio">' . $lang_util_php['update_both'] . '</label><br />
<input type="radio" name="updatetype" value="3" id="resize_original" class="nobg" /><label for="resize_original" accesskey="a" class="labelradio">' . $lang_util_php['update_originals'] . '</label><br />
// *** END *** Original Resize Mod ***
Hope this helps!
EXIF fix
----------
Oops, after some reading around, I realized that this resize will toast the EXIF information. To retain your EXIF info, apply the following modification to:
include/picmgmt.inc.php
around line 20, so, just after the comments and before add_picture function
if($CONFIG['read_exif_data'] ){
include("include/exif_php.inc.php");
}
and then find
// height/width
right around line 122 and just above that, insert:
// Before resizing image save exif info if required
if ($CONFIG['read_exif_data']) exif_parse_file($src_file);
I tested this today and it kept the EXIF and the IPTC info for the image

Linda