Hi there,

I was recently playing around with my drupal-system, and I accidentially changed my files location, which caused the image module to delete all references to different sizes (thumbnails) in the database - the files are still there, but drupal can't locate them...

Is there an easy way to fix this - cause image to recreate thumbnails or somthing like that?

Comments

fsimo’s picture

Hi, everyone,

I have a lot of problems with thumbnails in both 4.6 and 4.7, so I modify image.module for ensuring thmbnail and previews to be regenerates when database knows it has no thumb nor preview.

Here is my solution:
I added _image_build_derivatives($node); to the image_load function.

/**
 * Implementation of hook_load
 */
function image_load(&$node) {
  $result = db_query("SELECT filename, filepath FROM {files} WHERE nid=%d", $node->nid);
  $node->images = array();
  while ($file = db_fetch_object($result)) {
    $node->images[$file->filename] = $file->filepath;
  }
  // special images
  if (empty($node->images['thumbnail'])) {
    $node->images['thumbnail'] = $node->images['_original'];
     _image_build_derivatives($node);
  }
  if (empty($node->images['preview'])) {
    $node->images['preview'] = $node->images['_original'];
    _image_build_derivatives($node);
  }
}

So if you want to re-generate all thumbs you may also do

delete from files where filename='thumbnail';
delete from files where filename='preview';

If your problem was only not generated you only need to modify code.

--
http://fran.inhubi.com/

brunoslessa’s picture

I was having the same problem when I upgraded from the version 4.6 to the 4.7. The thumbnails were deleted in the database while I tried to see it, until I path the image module as fsimo told bewfore. But, I had to upload again every picture that I "saw" in my site before path the image module, this was needed to rebuild the thumbnail (problably there is a fast method to rebuild the thumbnail ...). The funny is that pictures I´ve not seen after the upgrade of the site is still ok, and I did not needed to rebuild it again.

Well, sorry for my poor english, and thanks Fran!

Bruno Lessa

Axel_V’s picture

Today somebody uploaded a gif to my site instead of a jpg and for the first time I've got that infamous error message:

getimagesize() [function.getimagesize]: Read error! in /homepages/18/d126859316/htdocs/newSiteDevelopment/Drupal/includes/image.inc on line 89.

Some of the respective posts on Drupal are pointing to the above patch and I patched the image.module accordingly. Unfortunaly now the error message shows twice!
Any other suggestions?

jorisx’s picture

Hmm same memory error here but

The code _image_build_derivatives($node);
really helped me out a bit :)

Nearly all thumbnails are regenerated :)

Thanks!

Http://www.reloadmedia.com

Disoculated’s picture

I had this problem in drupal 5.1 and your fix corrected it there too. Thanks!

hedac’s picture

thank you fsimo !

I got a problem that some random images lost their thumbnails, don't know why. and that simple fix solved the problem.

satori1984’s picture

+1

Thx alot m8 ! Those oversized thumbs were really getting on my nerves...

eferraiuolo’s picture

Thanks for the tip, adding those two lines of code corrected my problem on 5.1.

Once the problem was corrected (Drupal didn't have access to delete files from my files dir), and I got all my preview and thumbnail derivatives I just reverted the image.module back to its original code.

Thanks again!

kecinzer’s picture

I have the same problem, when i upgraded from 4.6 to 5.1. This works perfect.
Thanks.

alynner’s picture

great solution, worked for me on 4.7

alynner

webmastrnick’s picture

Stumbled upon this website thumbnails site on StumbleUpon, Added thier thumbnails to my website and they were captured in just a few seconds! Very reliable and fast from what I can tell, http://thumbnailspro.com

banglogic’s picture

I added the code from fsimo shown above in my 5.x install of Drupal.

The twin error messages...

The selected file could not be copied, because no file by that name exists. Please check that you supplied the correct filename.
The selected file could not be copied, because no file by that name exists. Please check that you supplied the correct filename.

...still pop up every time but at least the thumb and preview images still exist and everything works as before.

Many thanks fsimo!

I wonder if this issue will ever get worked out nice and proper. It seems to have been around since 4.6.

Ken Knicker
Bang Logic

equality’s picture

Hi,

I have used the code from above to regenerate and show the thumbnails with success, my problem now is that it keeps creating new thumbnails and previews everytime I visit the image node. Reverting the image.module back to original doesn't show the thumbnails, only the original size images.

Any idea please?

------------------
Igualdad Animal / Animal Equality :: against speciesism
http://www.igualdadanimal.org

nasi’s picture

This is the problem I am having as well. With the patch, all is displayed ok, but revert to the original code and I'm back where I started.

It's as if (with the patch applied) the derivatives are fixed while a page is being loaded, but the changes are not committed to the database.

If I edit an undamaged image I can see file attachments for the '_original', 'thumbnail' and 'preview' versions. But when I look at a damaged file (even with the patch) I only see the '_original' version.

I suspect this is why things break again with the patch removed but I can't work out how to commit the changes to the db and fix things for good…

RaRi’s picture

Nothing more to say .. but -
with the patch I get oversized thumbnails, without patch no image at all.

Using image.module,v 1.209.2.48 2007/09/29