Thumbnails not updating if new size is larger than the image

Started by Kays, June 06, 2013, 01:51:18 PM

Previous topic - Next topic

Kays

Posting this for reference. My repo is way out date else I'd do a commit also.

If the thumbnail size is changed and it is now larger that the existing image. If a thumbnail exists, it does not get resized and is still displayed at the old size.

http://www.simplemachines.org/community/index.php?topic=505297.msg3556832#msg3556832

Here is a fix for that. This will delete the thumbnail and update the database.

In Display.php look for:


if (!empty($attachment['id_thumb']))
$attachmentData[$i]['thumbnail'] = array(


And add before that:


// If the thumbnail size is increased and the image size is now smaller than that. Remove the old thumbnail so it don't show.
if (!empty($attachment['id_thumb']) && $attachment['width'] <= $modSettings['attachmentThumbWidth'] && $attachment['height'] <= $modSettings['attachmentThumbHeight'])
{
require_once($sourcedir . '/ManageAttachments.php');
removeAttachments(array('id_attach' => $attachment['id_thumb']), '', false, false);

$smcFunc['db_query']('', '
UPDATE {db_prefix}attachments
SET id_thumb = {int:id_thumb}
WHERE id_attach = {int:id_attach}',
array(
'id_thumb' => 0,
'id_attach' => $attachment['id_attach'],
)
);

$attachment['id_thumb'] = 0;
}


If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

feline

Better way .. create new thumbnails in the admin part, if the size changed. that will work for up- and downsize  ;D

shawnb61

Closing old 2.0 bugs - 2.0 is in security fixes-only at this point.
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

Advertisement: