While using the image module, I found that if I set the preview size to a size the same or larger than the original, the preview image that is generated is a copy of the original with "_0" added to the name of the file. For example: image_0.jpg.

If I go to image settings and click on "Save configuration," even without changing any settings, the original image will then show up as the preview image. The copy of the file with the "_0" is then no longer accessible. Is this normal?

I would like the original image to be used as the preview image by default if it's the same or smaller than the defined preview size so that identical copies don't take up extra server space. Is there a way to enable this?

Comments

Montuelle’s picture

Title: Use original image as preview » Duplicated files when orignal size ≤ preview size

I am running the CVS versions of Drupal 4.7 and image.module (with the patch in drupal.org/node/50889).

I also have the same problem: for all original images having a size equal or lower than the preview size there are duplicated files in files/images. For examples:

image1234.jpg
image1234.thumbnail.jpg
image1234_0.jpg

This is not the case in the files/images/temp folder:

image1234.jpg
image1234.thumbnail.jpg

In the database the preview points to image1234_0.jpg and _original to image1234.jpg

As in my case, I want to limit the space used by images by uploading original having the preview size (800x600) this is unfortunate because in fact I use twice the space really needed.

Montuelle’s picture

Version: 4.6.x-1.x-dev » 6.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new1.08 KB

This my first patch submission to Drupal. Be indulgent.

It is based on the fact that if a derivative is missing image_load() replaces it by the original. For example:

if (empty($node->images['preview'])) {
    $node->images['preview'] = $node->images['_original'];
{

So when the original is equal or smaller than the derivative, the derivative does not need to be created. It is what my patch does in image_insert() and in image_update()

I have tested when the original size == preview size. When original < thumbnail. I have also tried all sort of updates (to bigger or smaller images) and deletes. It seems to work.

Montuelle’s picture

I must add that you must also apply the patch in drupal.org/node/50889 to be able to run image.module with the CVS version of Drupal 4.7.

neclimdul’s picture

Code works as intended. I'd say this might cause a problem if images are resized if/when label sizes are changed but this doesn't happen anyways. This to me is a good idea and it works well with the link building patch.

Montuelle’s picture

James, thanks for your review. Could the status be changed to "ready to be committed"?

dtmatthes’s picture

When I tried to run the original_as_derivative.patch using Cygwin, I received the following message:

missing header for unified diff at line 2 of patch
(Stripping trailing CRs from patch.)
patching file image.module
patch: **** malformed patch at line 7: @@ -359,11 +359,13 @@

Thanks for your help.

dtmatthes’s picture

Can you point me to a resource that explains how to implement the original_as_derivative.patch, since I couldn't seem to get it to work by using the patch command and Cygwin.

Montuelle’s picture

In the Drupal handbook there is a chapter Patching with Cygwin.

But as it is my first patch, it could be a problem with the way I have produced it. I have used WinMerge on Windows. I will try to produce another version by using Diff from Gnuwin32. I will also save the file with "Linux line-ends". I am trying to figure out from drupal.org/diffandpatch how to do all this.

Sorry but I have never applied a patch directly on my server. For the rare cases where I needed to modify the Drupal source, I did it "by hand" (cut and paste with a text editor on my computer and then FTP upload).

Montuelle’s picture

StatusFileSize
new1.05 KB

Here is the patch file as produced by Eclipse on Windows and with unix line endings.
@dtmatthes: could you report if this is working for you now. Thanks.

neclimdul’s picture

I've been using this for a while now and haven't run into any problems.
+1 to commit

dtmatthes’s picture

Montuelle: The original_as_derivative_0.patch seemed to work just fine with Cygwin, and it seems to have fixed the original issue. Thanks!

walkah’s picture

Status: Needs review » Fixed

committed a modified version of this (centralized the check to _insert_image() ). thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)
Hetta’s picture

Version: 6.x-1.x-dev » 5.x-1.x-dev
Status: Closed (fixed) » Active

This is still a problem for both the dev version (May 27, 2007) and the production version (5.x-1.1, May 2, 2007).

It needs fixing, VERY badly.

drewish’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
Status: Active » Closed (fixed)

Hetta, i really appreciate that you looked for an existing issue before creating an new one but this has been closed for over a year and the code has changed enough between then and now that it's probably not the same bug. please open up a new issue for it.

Hetta’s picture

I believe this is the same issue as well: http://drupal.org/node/142233 - that one is still open.
Thanks!