Reducing thumbnail width

Get help with installation and running phpBB 3.1.x here. Please do not post bug reports, feature requests, or extension related questions here.
Anti-Spam Guide
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: phpBB 3.1.x is at its End of Life stage and support will NOT be provided after July 1st, 2018.
User avatar
shortmort37
Registered User
Posts: 541
Joined: Sat Aug 26, 2006 8:40 pm
Location: Upper Darby, PA, USA
Name: Dan Morton
Contact:

Reducing thumbnail width

Post by shortmort37 »

I currently have thumbnail width set to 600 in the attachment settings of the ACP. But, a portrait mode image that has been uploaded has a scaled thumbnail dimensions at 447 in width, and 600 in height.

Do I take it, that "thumbnail width" really means the longest dimension?

And, if I were to reduce the thumbnail width to, say, 400 - there would be no rescaling of previously uploaded thumbnails, correct? And a thumbnail whose width is now in excess of 400 pixels would continue to display?

If so... Is there any utility, that would rescale all priors thumbnails to the new width?

Thanks
Dan
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: Reducing thumbnail width

Post by canonknipser »

shortmort37 wrote:I currently have thumbnail width set to 600 in the attachment settings of the ACP. But, a portrait mode image that has been uploaded has a scaled thumbnail dimensions at 447 in width, and 600 in height.

Do I take it, that "thumbnail width" really means the longest dimension?
Well, it should happen as you set in acp: x-dimension is the horizontal axis, and y-dimension the vertical. I assume you set both to 600?

There are two different ways to generate an attachment thumbnail: imagemagick (which is the preferred one) and gd.
On my boards, i always had imagemagick active, and never recognized a problem with wrong thumbnail dimension. Can you check if imagemagick is active and used on your board?
Maybe gd doesn't check the orientation-flag within image meta data and has a problem to recognize that your image is portrait.

Edit: Just checked again: In the core code, there is a function which checks the original orientation and uses the parameter in acp as "longest edge" instead of "width".

So, this is a "works as designed" and the acp-parameter must be read as "longest edge".

shortmort37 wrote:And, if I were to reduce the thumbnail width to, say, 400 - there would be no rescaling of previously uploaded thumbnails, correct? And a thumbnail whose width is now in excess of 400 pixels would continue to display?
Yes, that's right. Existing thumbnails are not affected. If you don't want to resize your thumbnails and your older ones are bigger than the newer ones, you can add a rule to your css (must be in content.css

Code: Select all

dl.thumbnail img {
	padding: 3px;
	border: 1px solid transparent;
	box-sizing: border-box;
}

to set the max-width for a attachment thumbnail - i'm not good in css, so i didn't put any coding ;) ) This way you can present a smaller version of the current thumbnail ;)
shortmort37 wrote:Is there any utility, that would rescale all priors thumbnails to the new width?
No, there is none, but it should work with a relative simple script:
loop over your attachment_table,
for every entry, which has a thumbnail (column thumbnail = 1), check the current dimension (getimagesize-function), if they are bigger than allowed, call the generate_thumbnail-function from phpBB

I can try to build a script in the next days, if you are interested.
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
User avatar
shortmort37
Registered User
Posts: 541
Joined: Sat Aug 26, 2006 8:40 pm
Location: Upper Darby, PA, USA
Name: Dan Morton
Contact:

Re: Reducing thumbnail width

Post by shortmort37 »

Frank,

I am using ImageMagick. I don't see an option to set the maximum vertical thumbnail dimension - just the horizontal, which is set to 600. (My maximum image size is set to 5120x4096.). But since the photo in question came from my iPhone, I am sure the scaling was due to the metadata associated with the orientation.

I am thinking about a gallery style extension ( if I can figure it out - I've previously hacked 3.0.11 to employ), and I would like to go back and rescale my thumbs to 400. So yes, I would very much be interested in your script! Thanks.

Dan
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: Reducing thumbnail width

Post by canonknipser »

shortmort37 wrote:I am using ImageMagick. I don't see an option to set the maximum vertical thumbnail dimension - just the horizontal, which is set to 600. (My maximum image size is set to 5120x4096.). But since the photo in question came from my iPhone, I am sure the scaling was due to the metadata associated with the orientation.
Hi Dan, i edited my previous post before you answered because i misread your posting :oops: :
canonknipser wrote:Just checked again: In the core code, there is a function which checks the original orientation and uses the parameter in acp as "longest edge" instead of "width".

So, this is a "works as designed" and the acp-parameter must be read as "longest edge".
Maybe it is worth to report it to the bug tracker (because there is a change in the acp language file needed).
shortmort37 wrote:So yes, I would very much be interested in your script!
OK, i will try my best ;)
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: Reducing thumbnail width

Post by canonknipser »

So, here you are:

Code: Select all

<?php
/**
* This script will re-generate all thumbnails for attachments from the attachment folder (default
* "files"), useful after changing the thumbnail width (= longest edge) via acp
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);

// Name of script - change if you use a different name for the script
$scriptname = 'gen_thumb.php';
// Specify the number of attachments to handle in one run - reduce if you receive a timeout from server
$interval = 100;

// read id of last attachement copied
if (isset($config['last_thumb_id']))
{
    $last_thumb_id = $config['last_thumb_id'];
}
else
{
    $last_thumb_id = 0;
    set_config('last_thumb_id', 0);
}

// count number of attachments to process
$sql = 'SELECT COUNT(attach_id) AS num_attach FROM ' . ATTACHMENTS_TABLE . ' WHERE attach_id > ' . (int) $last_thumb_id . '  AND thumbnail = 1 ORDER BY attach_id ASC';
$result = $db->sql_query($sql);
$attachs_count = (int) $db->sql_fetchfield('num_attach');

// Output Information
echo dheader();

// read required information from attachment table
$sql = 'SELECT attach_id, physical_filename, mimetype FROM ' . ATTACHMENTS_TABLE . ' WHERE attach_id > ' . (int) $last_thumb_id . ' AND thumbnail = 1 ORDER BY attach_id ASC';
$result = $db->sql_query_limit($sql, $interval);

// how many attachment do we copy in this run?
$actual_num = $db->sql_affectedrows($result);
if ($actual_num == 0)
{
    // nothing to do
    $complete = true;
}
else
{
    $complete = false;
    if ($attachs_count <= $interval)
    {
        // this is the last run
        $complete = true;
    }
    while ($row = $db->sql_fetchrow($result))
    {
        // for each attachment
        //remember id
        $last_thumb_id = $row['attach_id'];
        // build source filename including path (we fetch the path from config
        $source = $phpbb_root_path . $config['upload_path'] . '/' . $row['physical_filename'];
        // build destination filename including path
        $destination = $phpbb_root_path . $config['upload_path'] . '/thumb_' . $row['physical_filename'];
        // copy the file

        if (create_thumbnail($source, $destination, $row['mimetype']))
        {
                // write info to user
                echo sprintf("<tr><td class='succ'>creation of thumbnail succesful:</td><td>%s</td><td>%s</td><td>%s</td></tr>", $last_thumb_id, $source, $destination);
        }
        else
        {
                echo sprintf("<tr><td class='error'>creation of thumbnail failed:</span></td><td>%s</td><td>%s</td><td>%s</td></tr>", $last_thumb_id, $source, $destination);
        }
    }
    // write last attachment id in config
    if ($complete)
    {
        $last_thumb_id = 0;
        set_config('last_thumb_id', 0);
    }
    else
    {
        set_config('last_thumb_id', $last_thumb_id);
    }
}
// finished
echo dfooter();

function dheader()
{
    global $attachs_count, $interval, $last_thumb_id;
    if ($interval > $attachs_count)
    {
        $interval = $attachs_count;
    }
    $remain = $attachs_count - $interval;

    return '<html>
    <head>
        <title>copy ' . $interval . ' attachments in this run, ' . $remain . ' remain to generate, starting with id '. $last_thumb_id .'</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf8">
        <style>
                a:visited {COLOR: #3A4273; TEXT-DECORATION: none}
                a:link {COLOR: #3A4273; TEXT-DECORATION: none}
                a:hover {COLOR: #3A4273; TEXT-DECORATION: underline}
                .error {COLOR: red; ; FONT-WEIGHT: bold}
                .succ {COLOR: green; ; FONT-WEIGHT: bold}
                body, table, td {COLOR: #3A4273; FONT-FAMILY: Tahoma, Verdana, Arial; FONT-SIZE: 12px; LINE-HEIGHT: 20px; scrollbar-base-color: #E3E3EA; scrollbar-arrow-color: #5C5C8D}
                input {COLOR: #085878; FONT-FAMILY: Tahoma, Verdana, Arial; FONT-SIZE: 12px; background-color: #3A4273; color: #FFFFFF; scrollbar-base-color: #E3E3EA; scrollbar-arrow-color: #5C5C8D}
                .install {FONT-FAMILY: Arial, Verdana; FONT-SIZE: 20px; FONT-WEIGHT: bold; COLOR: #000000}
        </style>
    </head>
    <body bgcolor="#3A4273\" text="#000000">
        <table width="95%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" align="center">
                <tr>
                    <td>
                        <table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
                                <tr><th colspan="4">copy ' . $interval . ' attachments in this run, ' . $remain . ' remain to generate, starting with id '. $last_thumb_id .'</th></tr>
                                <tr>
                                    <th>Status</th><th>Attach_ID</th><th>phpBB internal file name</th><th>generated thumbail</th>
                                </tr>';
}

function dfooter()
{
    global $scriptname, $complete;
    if (!$complete)
    {
        $next_step_link = '<a href="' . $scriptname . '">Click to continue with next step</a>';
    }
    else
    {
        $next_step_link = "<b>Completed</b>";
    }

    return '<tr><td colspan="4" align="center">' . $next_step_link . '</td></tr>
                        </table>
                    </td>
                </tr>
        </table><br>
    </body>
</html>';
}

?>
Testet on a local 3.1-board, but should also work on a 3.0 (this is a port from my Knowledge Base - Backing up attachments with their original filenames-article)

Save it as gen_thumb.php to the root-directory of your board and point to it with your browser (like http://yourboardroot.com/gen_thumb.php). Use at your own risk and make a copy (binary ftp) of your files-folder before!

It generates up to 100 thumbs in one run, you can change this value by modifying the $interval-variable.
You can restart the script for the next block of attachments by clicking the link at the bottom or just by refreshing your browser.
When all thumbs are regenerated, the next run will start from the beginning ;)
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
User avatar
shortmort37
Registered User
Posts: 541
Joined: Sat Aug 26, 2006 8:40 pm
Location: Upper Darby, PA, USA
Name: Dan Morton
Contact:

Re: Reducing thumbnail width

Post by shortmort37 »

Excellent! Many thanks, Frank - I will play with it this weekend.

Thanks again!
Dan
kocureq
Registered User
Posts: 143
Joined: Sat Apr 11, 2009 7:59 pm

Re: Reducing thumbnail width

Post by kocureq »

canonknipser wrote:It generates up to 100 thumbs in one run, you can change this value by modifying the $interval-variable.
You can restart the script for the next block of attachments by clicking the link at the bottom or just by refreshing your browser.
When all thumbs are regenerated, the next run will start from the beginning ;)
Any idea why some thumbs are failing why most of them is going fine?
Attachments
Zrzut ekranu 2016-08-27 o 17.07.00.png
User avatar
Lumpy Burgertushie
Registered User
Posts: 68556
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: Reducing thumbnail width

Post by Lumpy Burgertushie »

wild guess: maybe those attachments are not images but something else.



robert
I'm baaaaaccckkkk. still doing work on donation basis. PM your needs.

Premium phpBB 3.3 Styles by PlanetStyles.net

I am pleased to announce that I have completed the first item on my bucket list. I have the bucket.
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: Reducing thumbnail width

Post by canonknipser »

Lumpy Burgertushie wrote:wild guess: maybe those attachments are not images but something else.
If they weren't images, they should not have a thumbnail info in the database. The scripts reads all entries in attachment table with the thumbnail-flag set to true and uses the phpBB-core-functions to create the thumbnail file. So, a thumbnail must have been present at some point ...
kocureq wrote:Any idea why some thumbs are failing why most of them is going fine?
hard to say from the output, so can you give more information?
  • Are those really images or something else, as Robert guessed?
  • Are the files not broken (you can check it for the first file by typing the address yourboardaddress/download/file.php?id=36&mode=view, the image should be displayed)
  • Do you have ImageMagick active?
Can you post the row for the first failed entry (attach_id = 36) from the attachment table and also the corresponding file (maybe put it in a dropbox and give me the link via pm)
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
kocureq
Registered User
Posts: 143
Joined: Sat Apr 11, 2009 7:59 pm

Re: Reducing thumbnail width

Post by kocureq »

Yup, the particular one is an image - see http://fordprobe.pl/forum/download/file ... &mode=view

Attached you can find the database entry.
Attachments
Zrzut ekranu 2016-08-28 o 12.21.24.png
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: Reducing thumbnail width

Post by canonknipser »

OK, that looks fine - one reason for a non generated thumbnail can be:
your current image is smaller than the specified thumbnail dimensions - the image has 400px*300px, what is your acp setting for the thumbnail dimension?
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
kocureq
Registered User
Posts: 143
Joined: Sat Apr 11, 2009 7:59 pm

Re: Reducing thumbnail width

Post by kocureq »

Max width of a thumbnail is 400 px.
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: Reducing thumbnail width

Post by canonknipser »

So, as your image has already the minimum dimension (no edge is longer than 400px), therefore no thumbnail is generated
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
User avatar
shortmort37
Registered User
Posts: 541
Joined: Sat Aug 26, 2006 8:40 pm
Location: Upper Darby, PA, USA
Name: Dan Morton
Contact:

Re: Reducing thumbnail width

Post by shortmort37 »

Greetings Frank,

I'm rereading this post, now that I'm a bit smarter about css and html 5...
canonknipser wrote:If you don't want to resize your thumbnails and your older ones are bigger than the newer ones, you can add a rule to your css (must be in content.css

Code: Select all

dl.thumbnail img {
	padding: 3px;
	border: 1px solid transparent;
	box-sizing: border-box;
}

to set the max-width for a attachment thumbnail - i'm not good in css, so i didn't put any coding ;) ) This way you can present a smaller version of the current thumbnail ;)
It makes me wonder: If thumbnails can be scaled dynamically with css - wouldn't it be possible (with an extension), to always render a thumbnail of the desired size? i.e., eliminate creating and storing thumbnails on upload, and render the thumbnail from the unscaled image dynamically in accordance with the ACP setting on download?

Thanks
Dan
User avatar
Mick
Support Team Member
Support Team Member
Posts: 23057
Joined: Fri Aug 29, 2008 9:49 am

Re: Reducing thumbnail width

Post by Mick »

shortmort37 wrote:It makes me wonder: If thumbnails can be scaled dynamically with css - wouldn't it be possible (with an extension)
It doesn't hurt to make an extension request ;)
"The more connected we get the more alone we become" - Kyle Broflovski©
Locked

Return to “[3.1.x] Support Forum”