Coppermine creating Orig files, Watermark not enabled? Coppermine creating Orig files, Watermark not enabled?
 

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

Coppermine creating Orig files, Watermark not enabled?

Started by danvonerich, July 14, 2012, 05:27:53 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

danvonerich

For some reason i've noticed that my Coppermine Gallery is creating Orig files, but the Watermark Feature isnt enabled/ticked. Does anyone know how to stop Coppermine doing this?

Αndré

The responsible code part is
Code (include/picmgmt.inc.php) Select
        if (!file_exists($orig) && $CONFIG['enable_watermark'] == '1' && ($CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'original'))  {
            if (!copy($image, $orig)) {
                return false;
            } else {
                $work_image = $orig;
            }
        }


As you can see, it's not possible that Coppermine creates the backup files during upload. I haven't checked if they'll be created somewhere else in the code. Please check if those files will also be created for new uploads.

Niecher

I have this problem since a long time I activated the watermark. Currently I have it disabled.

but, whenever I upload an image or even replacing a file with the plugin "file_replacer" is created the file "orig_". This takes up too much disk space over time.

Using the tools "admin tools" I get a long list of files "orig_" created.

The only solution i've found, easily, has been left blank the corresponding box "Which file to use for watermark" on the gallery settings, section watermark. That is, removing "images/watermark.png".

Thus, when I run "admin tools" appears in the list the last file uploaded or replaced, for example in my case "The file albums/userpics/10003/orig_papermario.png was not found".

Has been registered but the file "orig_" has not been created, and not find it to delete it.

Best Regards.

Αndré

You're performing 3 different things here:

  • Uploading files
  • Replacing files
  • Admin tools

Please check carefully when exactly the the backup file is created. I.e. upload a picture to your gallery Which upload method do you use? Have you tested all 3? Now, check if the backup file exists. If so, delete it. Next, replace that file with the file_replacer plugin. Again, check if the backup file exists and delete it if necessary. Repeat that procedure for the admin tools.

Niecher

Hello André,

I enabled the watermark (i do not remember what version of coppermine)
and then i disabled the watermark, but the gallery was still creating archives "orig_" (for files uploaded by any method).

To avoid creating files "orig_" i had to remove "image/watermark.png".

Now i'm back to fill the field to this test. Here is the result:

"Watermark images" >> no selected
"Watermark custom thumbs (movie, audio, document)" >> no selected
"Which file to use for watermark" (images/watermark.png) >> both, with filled field or with blank field


  • Using "Upload.php"
          Admin tools notice: "The file albums/userpics/10002/orig_portada.jpg was not found"

  • Using "file_replacer"
          Admin tools notice: "None"

  • Using "Batch Files"
          Admin tools notice: "The file albums/uploads/Otros/test/orig_portada.jpg was not found"

If the file is removed from the gallery, the message "The file albums/uploads/Otros/test/orig_portada.jpg was not found" no longer appears.

Regards

jaus

I am seeing orig_ files created when running admin tools and selecting "update everything"  (watermarking turned off)

When I upload aaaa.jpg I get:

thumb_aaaa.jpg   (sized 128px)
normal_aaaa.jgg   (sized 500px)
aaaa.jpg   (sized 1000px)

If I then run admin tools->update thumbs/resized photos->Everything
orig_aaaa.jpg appears also with a size of 1000px

So, that leaves me with aaaa.jpg and orig_aaaa.jpg both with the same dimensions.   Is there a purpose to that?

Αndré

Unfortunately both of you haven't done what I asked for:
- Upload a new file (which upload method do you use?), check which files have been created and tell me (delete the orig_ file if it has been created).
- Replace a file with the file_replacer plugin, check which files have been created and tell me (delete the orig_ file if it has been created).
- Use the admin tools (which options have you set?), check which files have been created and tell me.

jaus

I don't have the file_replacer plugin, but I did do what you asked for in steps 1 and 3.   

I use the batch add process to upload files.   No 'orig_aaaa.jpg' version appears as a result of the upload, but it does appear after using admin tools (update everything), and appears to be an exact duplicate of the 'aaaa.jpg'.


Αndré


jaus

I installed the file_replacer plugin and tried your experiment:

After batch add of file aaaa.jpg the files in the folder are:
aaaa.jpg
normal_aaaa.jpg
thumb_aaaa.jpg

After replacing the file via file_replacer plugin the files :
aaaa.jpg
normal_aaaa.jpg
thumb_aaaa.jpg

After running admin tools using 'update everything':
orig_aaaa.jpg is added to the above three files and is identical to aaaa.jpg


Αndré

I need to have a closer look at the admin tools, as there are maybe some illogical code parts. To fix the issue you reported, open util.php, find
                    if (copy($image, $orig)) {
                        if ($CONFIG['enable_watermark'] == '1' && ($CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'original')) {

and replace with
                    if ($CONFIG['enable_watermark'] == '1' && ($CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'original')) {
                        if (copy($image, $orig)) {

Αndré

As you have to consider a lot of things while re-creating images, please regard the following as notes to myself.

Issues:
1. The current intermediate-sized block checks if an intermediate-sized file is needed and creates it, if the full-sized picture exceeds the intermediate limit. As this check is done before the full-sized picture will be resized (if needed), the current code will delete the intermediate-sized version in some cases, theoretically (haven't tested that).
2. The current full-sized block doesn't delete backup images if they're not needed anymore. To save space it should check if an original file exists if watermark is disabled and use this picture as full-sized version (overwriting the existing file).
3. No message is returned if the admin tools fail to create a backup image for the first time (need to add an else block).
4. The full-sized picture won't get resized if no backup image existed and watermark is disabled, as there's no corresponding else block.


I suggest to arrange the different blocks as it has been done in include/picmgmt.inc.php (I already optimized that code about 3 years ago, as it was also a mess like here). Then we just need to have a closer look at the full-sized block.

Αndré

Quote from: Αndré on August 27, 2013, 03:08:08 PM
4. The full-sized picture won't get resized if no backup image existed and watermark is disabled, as there's no corresponding else block.
That's maybe intended, as the image may look stupid if (different) watermarks are added in different sizes. A possibly applied watermark will get resized with the image and then a new watermark will be added, if enabled. However, as the user has been warned that the watermark will be permanent and IMHO it's more important to resize the picture, we should ignore this and resize the image anyway.

Αndré

Here's the optimized version which should fix all mentioned issues. I'm searching for volunteers who test this as thorough as possible (ideally at a copy of your gallery instead of your live gallery).

To apply it, open util.php, find
            if (file_exists($orig)) {
                $work_image = $orig;
                $orig_true = true;
            } else {
                $work_image = $image;
                $orig_true = false;
            }

            $imagesize = cpg_getimagesize($work_image);

            // Thumbnail
            if ($updatetype == 0 || $updatetype == 2 || $updatetype == 5) {
                if (resize_image($work_image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false", 1)) {
                    echo '<tr><td class="'.$tablestyle.'">' . $icon_array['ok'] . '<tt>' . $thumb .'</tt> '. $lang_util_php['updated_successfully'] . '!</td></tr>';
                } else {
                    echo '<tr><td class="'.$tablestyle.'">' . $icon_array['stop'] . $lang_util_php['error_create'] . ': <tt>' . $thumb.'</tt>!</td></tr>';
                }
            }

            // Intermediate size
            if ($updatetype == 1 || $updatetype == 2 || $updatetype == 3 || $updatetype == 5) {
                if ($CONFIG['make_intermediate'] && cpg_picture_dimension_exceeds_intermediate_limit($imagesize[0], $imagesize[1])) {
                    // intermediate sized picture is needed - create/update it
                    $resize_method = $CONFIG['picture_use'] == "thumb" ? ($CONFIG['thumb_use'] == "ex" ? "any" : $CONFIG['thumb_use']) : $CONFIG['picture_use'];
                    $watermark = ($CONFIG['enable_watermark'] == '1' && ($CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'resized')) ? 'true' : 'false';
                    if (resize_image($work_image, $normal, $CONFIG['picture_width'], $CONFIG['thumb_method'], $resize_method, $watermark)) {
                        echo '<tr><td class="'.$tablestyle.'">' . $icon_array['ok'] . '<tt>' . $normal . '</tt> ' . $lang_util_php['updated_successfully'] . '!</td></tr>';
                    } else {
                        echo '<tr><td class="'.$tablestyle.'">' . $icon_array['stop'] . $lang_util_php['error_create'] . ': <tt>' . $normal . '</tt>!</td></tr>';
                    }
                } elseif (file_exists($normal)) {
                    // intermediate sized picture isn't needed but exists - delete it
                    if (unlink($normal)) {
                        echo '<tr><td class="'.$tablestyle.'">' . $icon_array['ok'] . sprintf(str_replace('%s', '<tt>%s</tt>', $lang_util_php['del_intermediate']), $normal) . '!</td></tr>';
                    } else {
                        echo '<tr><td class="'.$tablestyle.'">' . $icon_array['stop'] . sprintf(str_replace('%s', '<tt>%s</tt>', $lang_util_php['del_error']), $normal) . '</td></tr>';
                    }
                } else {
                    // intermediate sized picture isn't needed and doesn't exists
                }
            }

            // Full sized
            if ($updatetype == 3 || $updatetype == 4 || $updatetype == 5) {

                if (max($imagesize[0], $imagesize[1]) > $CONFIG['max_upl_width_height'] && ((USER_IS_ADMIN && $CONFIG['auto_resize'] == 1) || (!USER_IS_ADMIN && $CONFIG['auto_resize'] > 0))) {
                    $resize_method = $CONFIG['picture_use'] == "thumb" ? ($CONFIG['thumb_use'] == "ex" ? "any" : $CONFIG['thumb_use']) : $CONFIG['picture_use'];
                    $max_size_size = $CONFIG['max_upl_width_height'];
                } else {
                    $resize_method = 'orig';
                    $max_size_size = max($imagesize[0], $imagesize[1]);
                }

                if ($orig_true == false) {
                    if (copy($image, $orig)) {
                        if ($CONFIG['enable_watermark'] == '1' && ($CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'original')) {
                            if (resize_image($work_image, $image, $max_size_size, $CONFIG['thumb_method'], $resize_method, 'true')) {
                                echo '<tr><td class="'.$tablestyle.'">' . $icon_array['ok'] . '<tt>' . $image . "</tt> " . $lang_util_php['updated_successfully'] . '!' . '</td></tr>';
                            } else {
                                echo '<tr><td class="'.$tablestyle.'">' . $icon_array['stop'] . $lang_util_php['error_create'] . ': <tt>' . $image . '</tt>!</td></tr>';
                            }
                        }
                    }
                } else {
                    if ($CONFIG['enable_watermark'] == '1' && ($CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'original')) {
                        if (resize_image($work_image, $image, $max_size_size, $CONFIG['thumb_method'], $resize_method, 'true')) {
                            echo '<tr><td class="'.$tablestyle.'">' . $icon_array['ok'] . '<tt>' . $image . "</tt> " . $lang_util_php['updated_successfully'] . '!' . '</td></tr>';
                        } else {
                            echo '<tr><td class="'.$tablestyle.'">' . $icon_array['stop'] . $lang_util_php['error_create'] . ': <tt>' . $image . '</tt>!</td></tr>';
                        }
                    } else {
                        if (max($imagesize[0], $imagesize[1]) > $CONFIG['max_upl_width_height'] && ((USER_IS_ADMIN && $CONFIG['auto_resize'] == 1) || (!USER_IS_ADMIN && $CONFIG['auto_resize'] > 0))) {
                            if (resize_image($work_image, $image, $max_size_size, $CONFIG['thumb_method'], $resize_method, 'false')) {
                                echo '<tr><td class="'.$tablestyle.'">' . $icon_array['ok'] . '<tt>' . $image . "</tt> " . $lang_util_php['updated_successfully'] . '!</td></tr>';
                            } else {
                                echo '<tr><td class="'.$tablestyle.'">' . $icon_array['stop'] . $lang_util_php['error_create'] . ': <tt>' . $image . '</tt>!</td></tr>';
                            }
                        } elseif (copy($orig, $image)) {
                            echo '<tr><td class="'.$tablestyle.'">' . $icon_array['ok'] . '<tt>' . $orig . "</tt> " . $lang_util_php['updated_successfully'] . '!</td></tr>';
                        } else {
                            echo '<tr><td class="'.$tablestyle.'">' . $icon_array['stop'] . $lang_util_php['error_create'] . ': <tt>' . $image . '</tt>!</td></tr>';
                        }
                    }
                }
            }

            $imagesize = cpg_getimagesize($image);

and replace with
            if (file_exists($orig)) {
                $work_image = $orig;
            } else {
                $work_image = $image;
            }

            $imagesize = cpg_getimagesize($work_image);

            if ($updatetype == 3 || $updatetype == 4 || $updatetype == 5) {
                // resize full-sized picture without watermark (will be applied later) if it's bigger than the max width or height for uploaded pictures
                if (max($imagesize[0], $imagesize[1]) > $CONFIG['max_upl_width_height']) {
                    if ((USER_IS_ADMIN && $CONFIG['auto_resize'] == 1) || (!USER_IS_ADMIN)) {
                        // skip resizing for admin if not set to "everyone"
                        $resize_method = $CONFIG['picture_use'] == "thumb" ? ($CONFIG['thumb_use'] == "ex" ? "any" : $CONFIG['thumb_use']) : $CONFIG['picture_use'];
                        if (resize_image($work_image, $image, $CONFIG['max_upl_width_height'], $CONFIG['thumb_method'], $resize_method, 'false')) {
                            $imagesize = cpg_getimagesize($image);
                            echo '<tr><td class="'.$tablestyle.'">' . $icon_array['ok'] . '<tt>' . $image . "</tt> " . $lang_util_php['updated_successfully'] . '!</td></tr>';
                        } else {
                            echo '<tr><td class="'.$tablestyle.'">' . $icon_array['stop'] . $lang_util_php['error_create'] . ': <tt>' . $image . '</tt>!</td></tr>';
                        }
                    }
                }
            }

            if ($updatetype == 0 || $updatetype == 2 || $updatetype == 5) {
                // resize thumbnail
                if (resize_image($work_image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false", 1)) {
                    echo '<tr><td class="'.$tablestyle.'">' . $icon_array['ok'] . '<tt>' . $thumb .'</tt> '. $lang_util_php['updated_successfully'] . '!</td></tr>';
                } else {
                    echo '<tr><td class="'.$tablestyle.'">' . $icon_array['stop'] . $lang_util_php['error_create'] . ': <tt>' . $thumb.'</tt>!</td></tr>';
                }
            }

            if ($updatetype == 1 || $updatetype == 2 || $updatetype == 3 || $updatetype == 5) {
                if ($CONFIG['make_intermediate'] && cpg_picture_dimension_exceeds_intermediate_limit($imagesize[0], $imagesize[1])) {
                    // intermediate sized picture is needed - create/update it
                    $resize_method = $CONFIG['picture_use'] == "thumb" ? ($CONFIG['thumb_use'] == "ex" ? "any" : $CONFIG['thumb_use']) : $CONFIG['picture_use'];
                    $watermark = ($CONFIG['enable_watermark'] == '1' && ($CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'resized')) ? 'true' : 'false';
                    if (resize_image($work_image, $normal, $CONFIG['picture_width'], $CONFIG['thumb_method'], $resize_method, $watermark)) {
                        echo '<tr><td class="'.$tablestyle.'">' . $icon_array['ok'] . '<tt>' . $normal . '</tt> ' . $lang_util_php['updated_successfully'] . '!</td></tr>';
                    } else {
                        echo '<tr><td class="'.$tablestyle.'">' . $icon_array['stop'] . $lang_util_php['error_create'] . ': <tt>' . $normal . '</tt>!</td></tr>';
                    }
                } elseif (file_exists($normal)) {
                    // intermediate sized picture isn't needed but exists - delete it
                    if (unlink($normal)) {
                        echo '<tr><td class="'.$tablestyle.'">' . $icon_array['ok'] . sprintf(str_replace('%s', '<tt>%s</tt>', $lang_util_php['del_intermediate']), $normal) . '!</td></tr>';
                    } else {
                        echo '<tr><td class="'.$tablestyle.'">' . $icon_array['stop'] . sprintf(str_replace('%s', '<tt>%s</tt>', $lang_util_php['del_error']), $normal) . '</td></tr>';
                    }
                }
            }

            if ($updatetype == 3 || $updatetype == 4 || $updatetype == 5) {
                if ($CONFIG['enable_watermark'] == '1' && ($CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'original')) {
                    // update/create backup of full sized picture if watermark is enabled for full sized pictures
                    if (copy($image, $orig)) {
                        echo '<tr><td class="'.$tablestyle.'">' . $icon_array['ok'] . '<tt>' . $orig . "</tt> " . $lang_util_php['updated_successfully'] . '!</td></tr>';
                    } else {
                        echo '<tr><td class="'.$tablestyle.'">' . $icon_array['stop'] . $lang_util_php['error_create'] . ': <tt>' . $orig . '</tt>!</td></tr>';
                    }
                    // watermark full sized picture
                    $wm_max_upl_width_height = (max($imagesize[0], $imagesize[1]) > $CONFIG['max_upl_width_height']) ? max($imagesize[0], $imagesize[1]) : $CONFIG['max_upl_width_height']; // use max aspect of original image if it hasn't been resized earlier
                    if (resize_image($work_image, $image, $wm_max_upl_width_height, $CONFIG['thumb_method'], 'any', 'true')) {
                        echo '<tr><td class="'.$tablestyle.'">' . $icon_array['ok'] . '<tt>' . $image . "</tt> " . $lang_util_php['updated_successfully'] . '!' . '</td></tr>';
                    } else {
                        echo '<tr><td class="'.$tablestyle.'">' . $icon_array['stop'] . $lang_util_php['error_create'] . ': <tt>' . $image . '</tt>!</td></tr>';
                    }
                } elseif (file_exists($orig)) {
                    // backup picture isn't needed but exists - delete it
                    if (unlink($orig)) {
                        echo '<tr><td class="'.$tablestyle.'">' . $icon_array['ok'] . sprintf(str_replace('%s', '<tt>%s</tt>', $lang_util_php['del_orig']), $orig) . '!</td></tr>';
                    } else {
                        echo '<tr><td class="'.$tablestyle.'">' . $icon_array['stop'] . sprintf(str_replace('%s', '<tt>%s</tt>', $lang_util_php['del_error']), $orig) . '</td></tr>';
                    }
                }
            }

Niecher

Hello André,

I get this error:

Fatal error: Call to undefined function cpg_picture_dimension_exceeds_intermediate_limit() in util.php on line 473


Regards

Αndré

That function has been added in cpg1.5.22. For testing purposes you can add that function to include/functions.inc.php:
function cpg_picture_dimension_exceeds_intermediate_limit($pwidth, $pheight) {
    global $CONFIG;

    $resize_method = $CONFIG['picture_use'] == "thumb" ? ($CONFIG['thumb_use'] == "ex" ? "any" : $CONFIG['thumb_use']) : $CONFIG['picture_use'];
    if ($resize_method == 'ht' && $pheight > $CONFIG['picture_width']) {
        return true;
    } elseif ($resize_method == 'wd' && $pwidth > $CONFIG['picture_width']) {
        return true;
    } elseif ($resize_method == 'any' && max($pwidth, $pheight) > $CONFIG['picture_width']) {
        return true;
    } else {
        return false;
    }
}

Niecher

Hello André,

This works perfectly.

The files "orig_" are no longer created.

Is there any way to remove the list of previously created files and that the files no longer exist? (If it can be, and if not possible ... no problem.)

Regards.  ;)

Αndré

Quote from: Niecher on August 27, 2013, 09:54:21 PM
Is there any way to remove the list of previously created files and that the files no longer exist? (If it can be, and if not possible ... no problem.)
What exactly do you mean? Please post some of that messages. Do they also appear with the updated code?

Niecher

For some time the gallery was creating files "orig_" and I knew nothing about the creation of these files even though the watermark was disabled.

when I used "Delete the original image backup for watermarked images" to check that the gallery did not create any new file, I have seen a long list of files "orig_" created in the past.

Is it possible to delete this file list "orig_"?

There are hundreds, this is a small indication only


The file albums/userpics/10071/orig_image35~8.png was not found
The file albums/userpics/10071/orig_image35~9.png was not found
The file albums/userpics/10071/orig_image35~10.png was not found
The file albums/userpics/10071/orig_image50~10.png was not found
The file albums/userpics/10071/orig_image13~10.png was not found
The file albums/userpics/10071/orig_image818.png was not found
The file albums/userpics/10071/orig_image1~6.png was not found
The file albums/userpics/10071/orig_image427.png was not found
The file albums/userpics/10071/orig_image430.png was not found
The file albums/userpics/10071/orig_image50~10.png was not found
The file albums/userpics/10071/orig_image13~10.png was not found
The file albums/userpics/10071/orig_image818.png was not found
The file albums/userpics/10071/orig_image1~6.png was not found
The file albums/userpics/10071/orig_image427.png was not found
The file albums/userpics/10071/orig_image430.png was not found


Regards

Αndré

I should have said that, but the code I changed currently affects only the "Update thumbs and/or resized photos" option. This is where I need as much information as possible if everything works as expected.

I'll have a closer look at the "Delete original image backup for watermarked images" option, as I agree that it doesn't make sense to flood the admin with such messages. Instead, we should just display if a file has been deleted or if there was an error deleting it. Should be an easy adjustment.