Advanced search  

News:

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

Pages: [1]   Go Down

Author Topic: How to resize your originals in Coppermine  (Read 37091 times)

0 Members and 1 Guest are viewing this topic.

lvanderb

  • Contributor
  • Coppermine newbie
  • ***
  • Offline Offline
  • Posts: 2
How to resize your originals in Coppermine
« on: August 21, 2004, 06:33:15 pm »

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
Code: [Select]
  'what_rebuild' => 'Rebuilds thumbnails and resized photos',and replace with
Code: [Select]
  'what_rebuild' => 'Rebuilds thumbnails, resized photos and original photos',
find
Code: [Select]
  'thumbs_wait' => 'Updating thumbnails and/or resized images, please wait...',
  'thumbs_continue_wait' => 'Continuing to update thumbnails and/or resized images...',
and replace with
Code: [Select]
  'thumbs_wait' => 'Updating thumbnails and/or resized/original images, please wait...',
  'thumbs_continue_wait' => 'Continuing to update thumbnails and/or resized/original images...',

find
Code: [Select]
  'update' => 'Update thumbs and/or resized photos',and replace with
Code: [Select]
  'update' => 'Update thumbs and/or resized photos or original photos',
insert the following
Code: [Select]
  '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
Code: [Select]
                    @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
Code: [Select]
                // *** 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
Code: [Select]
                    @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
Code: [Select]
                    // *** 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
Code: [Select]
        // *** 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
Code: [Select]
<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
Code: [Select]
// *** 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

Code: [Select]
if($CONFIG['read_exif_data'] ){
        include("include/exif_php.inc.php");
}

and then find
Code: [Select]
    // height/width right around line 122 and just above that, insert:
Code: [Select]
    // 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
« Last Edit: September 14, 2004, 08:59:08 am by GauGau »
Logged

Alejandrito

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 31
Re: How to resize your originals in Coppermine
« Reply #1 on: September 14, 2004, 08:30:49 am »

Hi!

What do you exactly mean with
Quote
Around 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
Code: [Select]
$startpic = $i;(Line 189) and
Code: [Select]
  if ($startpic < $totalpics) { (line 224)

I Click on Add file, then choose the file, then "Next", after that i get this message:
Quote
Successful 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.
« Last Edit: September 14, 2004, 09:15:09 am by matosale »
Logged

TranzNDance

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Female
  • Posts: 6148
    • Take Thu! Gallery
Re: How to resize your originals in Coppermine
« Reply #2 on: September 14, 2004, 11:23:34 am »

Hi!

What do you exactly mean with
Quote
Around 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.
Logged

Alejandrito

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 31
Re: How to resize your originals in Coppermine
« Reply #3 on: September 14, 2004, 12:56:42 pm »

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:

Quote
memory_limit = 10M
and
Quote
upload_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
« Last Edit: September 14, 2004, 02:27:07 pm by matosale »
Logged

edgarg

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 25
    • Oblonga disrupcion visual
Re: How to resize your originals in Coppermine
« Reply #4 on: October 24, 2004, 04:46:43 pm »

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
Logged

bibendum

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 51
Re: How to resize your originals in Coppermine
« Reply #5 on: February 20, 2005, 12:26:37 am »

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

 

Logged

cameron122000

  • Coppermine newbie
  • Offline Offline
  • Posts: 13
Re: How to resize your originals in Coppermine
« Reply #6 on: March 22, 2005, 07:23:32 am »

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?
Logged

TranzNDance

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Female
  • Posts: 6148
    • Take Thu! Gallery
Re: How to resize your originals in Coppermine
« Reply #7 on: March 22, 2005, 07:30:30 am »

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

Cenobitez

  • Coppermine newbie
  • Offline Offline
  • Gender: Male
  • Posts: 15
  • U cant run with the Hare, and hunt with the Hounds
    • Skindustrial
Re: How to resize your originals in Coppermine
« Reply #8 on: April 20, 2005, 11:24:32 am »

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 ?
Logged

TranzNDance

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Female
  • Posts: 6148
    • Take Thu! Gallery
Re: How to resize your originals in Coppermine
« Reply #9 on: April 20, 2005, 04:38:48 pm »

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.
Logged

wynode

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Re: How to resize your originals in Coppermine
« Reply #10 on: May 10, 2005, 03:56:24 am »

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

RF

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 20
Re: How to resize your originals in Coppermine
« Reply #11 on: June 04, 2005, 05:06:30 am »

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
Logged
john

Summi

  • Coppermine newbie
  • Offline Offline
  • Posts: 15
Re: How to resize your originals in Coppermine
« Reply #12 on: July 13, 2005, 05:08:10 pm »

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
Logged

Summi

  • Coppermine newbie
  • Offline Offline
  • Posts: 15
Re: How to resize your originals in Coppermine
« Reply #13 on: July 20, 2005, 05:58:26 pm »

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
Logged

TopShelfExotics

  • Coppermine newbie
  • Offline Offline
  • Posts: 6
    • Top Shelf Exotics
Re: How to resize your originals in Coppermine
« Reply #14 on: August 17, 2005, 11:12:03 am »

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

claude258

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 150
    • Album photos Brière
Re: How to resize your originals in Coppermine
« Reply #15 on: October 26, 2005, 04:10:56 am »

Quote
Re: 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? ???
Logged

daviddubree

  • Coppermine newbie
  • Offline Offline
  • Posts: 6
Re: How to resize your originals in Coppermine
« Reply #16 on: August 01, 2006, 06:33:47 pm »

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.
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47844
  • aka "GauGau"
    • gaugau.de
Re: How to resize your originals in Coppermine
« Reply #17 on: August 01, 2006, 10:52:03 pm »

Logged
Pages: [1]   Go Up
 

Page created in 0.026 seconds with 21 queries.