I am having a problem inserting the same image as a custom image in two different nodes. I get an insert error:
user warning: Duplicate entry '220-img_assist_custom' for key 1 query: INSERT INTO image (nid, image_size, fid) VALUES (220, 'img_assist_custom', 20420) in /home/.../database.mysql.inc on line 172.
The image, node 220, already exists in a different node, with a different fid. I am assuming the problem is that the 'image_size' field is supposed to be unique. Is this necessary? How can I add the same image into different nodes at custom sizes?

Many thanks,
Maria

CommentFileSizeAuthor
#5 img_assist-216978-080630.patch2.13 KBzoo33

Comments

mariagwyn’s picture

Priority: Normal » Critical

Upping this to critical, since it is proving to be a major problem on my site.

One possible solution, which I suggested on another issue, is that the 'custom_img' does not actually create a new image file, but simply displays the image at the requested size (i.e., the default 'preview', which is actually a 600x600 image, displays at the custom site setting, say, 150x150.) This way, all that is really recorded for img_assist is a custom size, not a new file, thus, no conflicts in the DB with the identical names.

Thanks,
Maria

akahn’s picture

I'm also experiencing this issue (#231657: Duplicate entry img_assist_custom error messages). Any comment from a developer on a possible solution?

lee20’s picture

Subscribing....

ja_ro_no’s picture

Any update on this issue? This is causing problems on my site as well.

zoo33’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new2.13 KB

So, the problem is that Image only allows one copy of each size label for each image node, which is natural. But Image assist has the ability to create more than one custom size. The solution is to change the size label from "img_assist_custom" to "img_assist_custom-XXXxYYY". Turns out to be a simple one-liner. However:

I removed a comment and one line of code which seems to have been meant to be used to avoid this very issue. However, the assigned variable, $page_nid, is never used.

I added an update function to remove all old custom images. They will be regenerated with the new naming standard regardless of this, so I thought it would be nice to get rid of the images that won't be used after this point. Or would it be better to let them stay so that old manual image links still work?

Testers may want to skip the update function for now if they don't know how to roll back the module to a previous state – the patch will work anyway.

This patch is for Drupal 6 but can easily be backported later.

Thanks to sun for the original idea on how to solve this issue.

sun’s picture

Status: Needs review » Reviewed & tested by the community

Boy, you rock!

Works perfectly, as the following output of Devel load proves:

$node->images (array, 6 elements)

    $node->images['_original'] (string, files/images/33.jpg)
        files/images/33.jpg 
    $node->images['thumbnail'] (string, files/images/33.thumbnail.jpg)
        files/images/33.thumbnail.jpg 
    $node->images['preview'] (string, files/images/33.preview.jpg)
        files/images/33.preview.jpg 
    $node->images['img_assist_properties'] (string, 41 characters)
        files/images/33.img_assist_properties.jpg 
    $node->images['img_assist_custom-120x148'] (string, 45 characters)
        files/images/33.img_assist_custom-120x148.jpg 
    $node->images['img_assist_custom-220x272'] (string, 45 characters)
        files/images/33.img_assist_custom-220x272.jpg 

sun’s picture

Title: Identical image in different nodes » Allow different custom image sizes for an image
Version: 6.x-1.x-dev » 6.x-2.x-dev
Category: bug » feature
Priority: Critical » Normal
Status: Reviewed & tested by the community » Fixed

Committed to HEAD, 6.x-2.x, and 5.x-2.x.

Let's make 2.x the best release ever!

sun’s picture

Just a quick note: I have left out that module update in img_assist.install, because I don't think we really need or want to delete existing images.

zoo33’s picture

Agreed. They won't be a problem. Rock on!

mariagwyn’s picture

sorry if this is dumb, but where do I get 5.x-2.x? I want to try it on the site I am fixing, but am not ready to jump to 6.x until I get 5.x working well.

Thanks,
Maria

zoo33’s picture

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.