How to resize your originals in Coppermine How to resize your originals in Coppermine
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

How to resize your originals in Coppermine

Started by lvanderb, August 21, 2004, 06:33:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

lvanderb

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  ;D

Linda

Alejandrito

#1
Hi!

What do you exactly mean with
QuoteAround line 187, insert the following

Shouldn't that be a little bit more specific? I'm new with coppermind, but i was working with 4images and as long as I know, the changes must be exacts in order to make it work...at least in PHP (or maybe I'm wrong?  ;) )

EDIT: well i put that part between
$startpic = $i;
(Line 189) and
  if ($startpic < $totalpics) { (line 224)

I Click on Add file, then choose the file, then "Next", after that i get this message:
QuoteSuccessful Uploads
1 uploads were successful.

Please click 'Continue' to add the files to albums.

But when i click on "next" nothing happens! no file is added or anything.

Thanks in advance for your help.

Tranz

Quote from: matosale on September 14, 2004, 08:30:49 AM
Hi!

What do you exactly mean with
QuoteAround line 187, insert the following

Shouldn't that be a little bit more specific?
Yes, the mod instructions should not depend upon line numbers. Not everyone has access to a text editor that shows line numbers. Or, people who have previously modified their files won't have the same code at a particular line number. However, everyone should be able to use Find to search particular code.

Alejandrito

#3
Well it seams that I put it in the right place. I had to make some changes thou.

After looking the php.ini file, I put:

Quotememory_limit = 10M
and
Quoteupload_max_filesize = 4M

So, now i do can upload big files, but those files are not being resized! :o  they still are really big (1600x1200!!!!)

If you want to see the content of the that were modified:

http://alex.no-ip.biz/upload.phps
http://alex.no-ip.biz/utils.phps

edgarg

any info on the line 182 stufff...... newbie here and I do not have an editor with line number I tried already but messed up I think i put it in the middle of something... luckyly I had a backup.

cheers

bibendum

Hi

This mod is working perfectly for me !!!

In setup, i only allowed 800x600 pictures.

With anonymous, i've try to send 1500x1200 picture, all is perfect, picture was resized to 800x600 automaticly.

Thanks a lot




cameron122000

Doesn't the gallery already have this? Like, right when you upload the pic, the gallery automatically creates the thumbnail and such? Or is this to just make the pic a different size after you had already uploaded it?

Tranz

By default, coppermine does not change the original files. Instead, it creates an intermediate-sized copy. This mod changes the original file.

Cenobitez

With the Edits to util.php do the extra lines go BEFORE the closing brace } or after the closing brace ? as like 187 is a } ?

Anyone any idea ?

Tranz

This is why it's better to show location by code rather than line numbers, which would vary based on previous modifications.

It should be before the closing brace, but I would wait for the author to tell you if that is correct.

wynode

Thanks for that...........Its just what I was looking for andd works fine! :)

RF

i applied this mod to my gallery.. and it seems to be working well.... uploaded pictures are resized as intended...

HOWEVER, when I used the resize originals under admin tools... instead of resizing it's replacing the original image with one specific image... weird... now the 45 or so pictures that I tested to resize all appear to be the same picture.... any idea what i did wrong....

please help
john

Summi

Hi,

I've got 2 problems with this mod (with cop.-version 1.3.3):

First, when i start the new resize-function in the admin tool section, i get this error...

Warning: mysql_result(): Unable to jump to row 2 on MySQL result index 9 in E:\xampp\htdocs\_testdaten\cpg133\util.php on line 192
Warning: mysql_result(): Unable to jump to row 2 on MySQL result index 9 in E:\xampp\htdocs\_testdaten\cpg133\util.php on line 192
Warning: mysql_result(): Unable to jump to row 2 on MySQL result index 9 in E:\xampp\htdocs\_testdaten\cpg133\util.php on line 193
Warning: mysql_result(): Unable to jump to row 2 on MySQL result index 9 in E:\xampp\htdocs\_testdaten\cpg133\util.php on line 193


Second:

Is it possible, that the batch function could use the resize mod, so that new "batch" pics are also resized automatically

Thanx, Summi

Summi

Hi again,

the first problem (error message) is solved, the resize function at the admin tool is working fine.

But i need your help by integrating the automatically resizing function into the batch uploading.

I think i have to mod the serchnew.php, but i don't know how to mod this.

Thanxs,
Summi

TopShelfExotics

this hack worked perfectly for us, thank you so much  ;D
C. Johnson
Owner - Top Shelf Exotics
http://topshelfexotic.com

claude258

QuoteRe: How to resize your originals in Coppermine
« Reply #11 on: June 03, 2005, 11:06:30 PM »   

--------------------------------------------------------------------------------
i applied this mod to my gallery.. and it seems to be working well.... uploaded pictures are resized as intended...

HOWEVER, when I used the resize originals under admin tools... instead of resizing it's replacing the original image with one specific image... weird... now the 45 or so pictures that I tested to resize all appear to be the same picture.... any idea what i did wrong....

please help



I have exactly the same problem.
Anybody have an idea of the problem? ???

daviddubree

Is this good for cpg 1.4.x ??

Is there a new mod that does this now for 1.4.x ? (resize originals long after upload)

Thanks
This mod is exactly what I need.

Joachim Müller