[4037]New thumbs created when attachment thumbs are resized

Started by Kays, November 30, 2009, 09:29:06 AM

Previous topic - Next topic

Kays

If there are existing thumbnails and the thumbmail size for attachments is changed, a new thumbnail is created and entered into the database. Leaving the original thumbnail on the server and the entry for it in the database intact. But without an image pointing at it.

I've noticed this behaviour with 1.1 as well as 2.0. As you can see in the code below from Display.php, no provisions are made to update an exising thumbnail. This is 1.1, the code is similar for 2.0


// Let's see, do we want thumbs?
if (!empty($modSettings['attachmentThumbnails']) && !empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachment['width'] > $modSettings['attachmentThumbWidth'] || $attachment['height'] > $modSettings['attachmentThumbHeight']) && strlen($attachment['filename']) < 249)
{
// A proper thumb doesn't exist yet? Create one!
if (empty($attachment['ID_THUMB']) || $attachment['thumb_width'] > $modSettings['attachmentThumbWidth'] || $attachment['thumb_height'] > $modSettings['attachmentThumbHeight'] || ($attachment['thumb_width'] < $modSettings['attachmentThumbWidth'] && $attachment['thumb_height'] < $modSettings['attachmentThumbHeight']))
{
$filename = getAttachmentFilename($attachment['filename'], $attachment['ID_ATTACH'], false, $attachment['file_hash']);

require_once($sourcedir . '/Subs-Graphics.php');
if (createThumbnail($filename, $modSettings['attachmentThumbWidth'], $modSettings['attachmentThumbHeight']))
{
// Calculate the size of the created thumbnail.
list ($attachment['thumb_width'], $attachment['thumb_height']) = @getimagesize($filename . '_thumb');
$thumb_size = filesize($filename . '_thumb');

$thumb_filename = addslashes($attachment['filename'] . '_thumb');

// Add this beauty to the database.
$thumb_hash = getAttachmentFilename($thumb_filename, false, true);
db_query("
INSERT INTO {$db_prefix}attachments
(ID_MSG, attachmentType, filename, file_hash, size, width, height)
VALUES ($ID_MSG, 3, '$thumb_filename', '$thumb_hash', " . (int) $thumb_size . ", " . (int) $attachment['thumb_width'] . ", " . (int) $attachment['thumb_height'] . ")", __FILE__, __LINE__);
$attachment['ID_THUMB'] = db_insert_id();
if (!empty($attachment['ID_THUMB']))
{
db_query("
UPDATE {$db_prefix}attachments
SET ID_THUMB = $attachment[ID_THUMB]
WHERE ID_ATTACH = $attachment[ID_ATTACH]
LIMIT 1", __FILE__, __LINE__);

$thumb_realname = getAttachmentFilename($thumb_filename, $attachment['ID_THUMB'], false, $thumb_hash);
rename($filename . '_thumb', $thumb_realname);
}
}
}

$attachmentData[$i]['width'] = $attachment['thumb_width'];
$attachmentData[$i]['height'] = $attachment['thumb_height'];
}

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

Norv

Confirmed on the latest svn, thank you for the report!
To-do lists are for deferral. The more things you write down the later they're done... until you have 100s of lists of things you don't do.

File a security report | Developers' Blog | Bug Tracker


Also known as Norv on D* | Norv N. on G+ | Norv on Github

Advertisement: