[RC1] Thumbnail-on-Dimensions mod (for Attachment mod)

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
Pseudonym
Registered User
Posts: 173
Joined: Mon Jan 26, 2004 8:37 am

[RC1] Thumbnail-on-Dimensions mod (for Attachment mod)

Post by Pseudonym » Mon Jun 27, 2005 9:37 am

This mod is designed to be installed on top of the Attachment mod. It will enable you to display a thumbnail image if the original image dimensions exceed a certain size.

I've been searching for an answer to this for months now - I've asked the question several times, and found plenty of people asking the same thing, but no-one has an answer. Hopefully this mod will solve the problem.

What the Attachment mod does now:
It currently has an option to create thumbnails if the filesize is too large. And there's an option to create a text link if the image exceeds the preset dimensions. But to create a thumbnail triggered by image dimension seems impossible!

What the Attachment mod (with this Thumbnail-on-Dimensions mod) will do:
The thumbnail will be created only if it exceeds a certain size, say 800x640. Anything smaller, no thumbnail, anything bigger, create thumbnail.
Last edited by Pseudonym on Fri Aug 12, 2005 11:31 am, edited 2 times in total.

Pseudonym
Registered User
Posts: 173
Joined: Mon Jan 26, 2004 8:37 am

Post by Pseudonym » Mon Jun 27, 2005 9:40 am

This mod has now been officially approved, and is available at http://www.phpbb.com/phpBB/viewtopic.ph ... torder=asc
Last edited by Pseudonym on Tue Feb 21, 2006 9:20 am, edited 6 times in total.

Pseudonym
Registered User
Posts: 173
Joined: Mon Jan 26, 2004 8:37 am

Post by Pseudonym » Mon Jun 27, 2005 9:46 am

Now the only thing that concerns me is how I've had to do a FIND for the same code twice in displaying.php. The problem is, the original file has the same code in two places - and both need changing. How does EasyMod cope with this?

Pseudonym
Registered User
Posts: 173
Joined: Mon Jan 26, 2004 8:37 am

Post by Pseudonym » Wed Jun 29, 2005 8:59 am

BUMP now that we've reached the beta version! :D

Any testers would be greatly appreciated.

User avatar
Tux_Rules
Registered User
Posts: 958
Joined: Sat Apr 24, 2004 10:48 pm
Location: Afton, Michigan
Contact:

Post by Tux_Rules » Sun Jul 17, 2005 8:11 pm

This is a nice addition to the Atachment MOD :D . Works nice and is esy to install. The only thing I changed is I droped the:

Code: Select all

style="float:left; margin: 5px;"
from /viewtopic_attach_body.tpl, as I like it all centered. I wil, if you have no objections, post this code on my forum. 8)

Pseudonym
Registered User
Posts: 173
Joined: Mon Jan 26, 2004 8:37 am

Post by Pseudonym » Tue Jul 26, 2005 10:53 am

Bah! Centered-schmentered! What could be nicer than left-aligned floats?! :D

I have no objections to you using the code at all. That's what it's here for...


One thing I've noticed is that of course it doesn't work in retrospect - images that were posted before the mod was installed will not have thumbnails created for them. This means the the thumbnail will be "redexed" Image - although the link to the full image works fine.

I know there's a script used in the Attachment mod install that goes through and creates thumbnails where needed. Do you think it would still work here?

User avatar
Tux_Rules
Registered User
Posts: 958
Joined: Sat Apr 24, 2004 10:48 pm
Location: Afton, Michigan
Contact:

Post by Tux_Rules » Sun Jul 31, 2005 8:56 pm

Pseudonym wrote: Bah! Centered-schmentered! What could be nicer than left-aligned floats?! :D

I have no objections to you using the code at all. That's what it's here for...


One thing I've noticed is that of course it doesn't work in retrospect - images that were posted before the mod was installed will not have thumbnails created for them. This means the the thumbnail will be "redexed" Image - although the link to the full image works fine.

I know there's a script used in the Attachment mod install that goes through and creates thumbnails where needed. Do you think it would still work here?

:mrgreen:
Bah! Centered-schmentered! What could be nicer than left-aligned floats?! :D
:mrgreen:

I think the thumbnail script might work, but when I used your MOD on my test site, there were no redx pics.

Pseudonym
Registered User
Posts: 173
Joined: Mon Jan 26, 2004 8:37 am

Post by Pseudonym » Fri Aug 12, 2005 11:22 am

Well, I finally got around to testing that thumbnail-creation file, and it appears to work perfectly.

The file is included with the Attachment Mod in the /scripts/ folder. It's called, strangely enough, create_thumbnails.php and it comes with a readme in the same folder.

johnny-legend
Registered User
Posts: 14
Joined: Wed Nov 30, 2005 11:29 pm

Post by johnny-legend » Sat Dec 17, 2005 4:24 pm

Well, not working for me..

Image

Pseudonym
Registered User
Posts: 173
Joined: Mon Jan 26, 2004 8:37 am

Post by Pseudonym » Sun Jan 15, 2006 8:52 am

Hi Johnny, and apologies for the delayed response. I've since updated the mod and resubmitted it to the mod database. You can either wait for it to be approved (hopefully!), or you can get it from the code I've posted above.

Having said that, it looks as though your problem is that thumbnails may not exist for images posted before the mod was installed. If that's the case, you need to run the thumbnail-creation file. The file is included with the Attachment Mod in the /scripts/ folder. It's called, strangely enough, create_thumbnails.php and it comes with a readme in the same folder.

firocious
Registered User
Posts: 6
Joined: Mon Feb 13, 2006 5:35 am

Post by firocious » Mon Feb 13, 2006 7:43 am

Hi there,

What is the secret to get this to work with Easy Mod?

I have EM v0.30 installed and have put this install file at:

/forum/admin/mods/Thumbnails-On-Dimensions/Thumbnails-On-Dimensions

But EM says "All mods processed."

Thanks.

firocious
Registered User
Posts: 6
Joined: Mon Feb 13, 2006 5:35 am

Post by firocious » Mon Feb 13, 2006 9:40 am

ok .. figured it out ... the mod file needed a ".txt" extension - which it was missing - so all is good now :D

Pseudonym
Registered User
Posts: 173
Joined: Mon Jan 26, 2004 8:37 am

Post by Pseudonym » Tue Feb 14, 2006 3:07 am


Pseudonym
Registered User
Posts: 173
Joined: Mon Jan 26, 2004 8:37 am

Post by Pseudonym » Sat Feb 25, 2006 6:24 am

This is the contents of the Attachment Mod's /scripts/create_thumbnails.php file from version 2.3.9. The entire /scripts/ folder seems to be no longer included in the latest versions, so I'm putting it up here for safe-keeping in case people want to find it.

NOTE: I'm not sure whether this is compatible with the latest Attachment Mod versions, so take a backup of your site first, and use at your own risk!

All scripts here have to be copied to the phpBB2 Root Directory (if the Instructions says to run the file) and don't forget to delete them after execution.


create_thumbnails.php:
If you want to create thumbnails from already existing Attachments this is the file you need. :)
Before you use this script, please make sure you have visited the Special Category Screen
in your Administration Panel to search for the imagick program and to make sure you have
enabled Thumbnail Creation and tested the Settings.
After you have done so, Upload the script to your phpBB2 Directory and execute it.
You have to choose whether to create thumbnails manually (You can choose the Attachment) or
to create the Thumnails automatically, without any action required from you.
If you choose the manual way and the Attachment where you clicked on (Create Thumbnail Link)
does not disappear from the list, the Thumnail Creation does not worked for this Attachment.

Code: Select all

<?php

//
// Create Thumbnails from all Attachments
// $Id: create_thumbnails.php,v 1.5 2003/06/18 17:53:01 acydburn Exp $
//

error_reporting  (E_ERROR | E_WARNING | E_PARSE); // This will NOT report uninitialized variables
set_magic_quotes_runtime(0); // Disable magic_quotes_runtime

define('IN_PHPBB', true);

$phpbb_root_path = './';
include($phpbb_root_path.'extension.inc');
include($phpbb_root_path.'common.'.$phpEx);	

if ( (!defined('ATTACH_VERSION')) || ( (!strstr(ATTACH_VERSION, '2.3.')) ) )
{
	message_die(GENERAL_MESSAGE, 'Only Version 2.3.x supported.');
}

$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);

if ( ($userdata['user_level'] != ADMIN) || (!$userdata['session_logged_in']) )
{
	message_die(GENERAL_MESSAGE, 'You are not authorized to execute this script, sorry, only the Administrator is allowed to do so.');
}

//
// BEGIN Functions

// END Functions
//

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css">
<!--

font,th,td,p,body { font-family: "Courier New", courier; font-size: 11pt }

a:link,a:active,a:visited { color : #006699; }
a:hover		{ text-decoration: underline; color : #DD6900;}

hr	{ height: 0px; border: solid #D1D7DC 0px; border-top-width: 1px;}

.maintitle,h1,h2	{font-weight: bold; font-size: 22px; font-family: "Trebuchet MS",Verdana, Arial, Helvetica, sans-serif; text-decoration: none; line-height : 120%; color : #000000;}

.ok {color:green}

/* Import the fancy styles for IE only (NS4.x doesn't use the @import function) */
@import url("templates/subSilver/formIE.css"); 
-->
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#006699" vlink="#5584AA">

<table width="100%" border="0" cellspacing="0" cellpadding="10" align="center"> 
	<tr>
		<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td><img src="templates/subSilver/images/logo_phpBB.gif" border="0" alt="Forum Home" vspace="1" /></td>
				<td align="center" width="100%" valign="middle"><span class="maintitle">Create Thumbnails</span></td>
			</tr>
		</table></td>
	</tr>
</table>

<br clear="all" />

<?php

$migrate_auto = ( isset($HTTP_GET_VARS['migrate_auto']) ) ? TRUE : FALSE;
$migrate_manual = ( isset($HTTP_GET_VARS['migrate_manual']) ) ? TRUE : FALSE;
$create_thumbnail = ( isset($HTTP_GET_VARS['create_thumbnail']) ) ? TRUE : FALSE;

if ($create_thumbnail)
{
	$attach_id = intval($HTTP_GET_VARS['create_thumbnail']);
}

$sql = "SELECT COUNT(*) as total FROM " . ATTACHMENTS_DESC_TABLE . "
	WHERE (thumbnail = 0) AND (mimetype LIKE '%image%')
	LIMIT 100";

if ( !($result = $db->sql_query($sql)) )
{
	$sql_error = $db->sql_error();
	print 'Could not query attachment informations - SQL ERROR:<br />';
	print $sql_error['code'] . ": ". $sql_error['message']. "<br>\n";
	die('Executed SQL Statement: <br />' . $sql);
}

$row = $db->sql_fetchrow($result);
$total = intval($row['total']);

if ($total == 0)
{
	die ('Nothing to convert here');
}

if ( (!is_imagick()) && (count(get_supported_image_types()) == 0) )
{
	die ('Unable to create thumbnails. This Server has no imagick installed and no GD Extensions Installed.');
}

//
// Let the User choose whether to review all Attachments or to do the convert automatically
//
if ( (!$migrate_auto) && (!$migrate_manual) )
{
	echo "<br />There are <b>" . $total . "</b> potential Attachments to create Thumbnails from.<br />";
	echo 'Do you want to try creating Thumnails from them automatically, please click this link: <a href="create_thumbnails.php?migrate_auto=1">Automatic Thumbnail Creation</a><br />';
	echo 'Do you want to try creating Thumnails from them manually (you will see the Attachment and then you are able to choose to create a Thumbnail from it or not), please click this link: <a href="create_thumbnails.php?migrate_manual=1">Manual Thumbnail Creation</a><br />';
}

if ( ($migrate_manual) && ($create_thumbnail) )
{
	$update_ids = array();

	$sql = "SELECT * FROM " . ATTACHMENTS_DESC_TABLE . "
	WHERE attach_id = " . $attach_id;

	if ( !($result = $db->sql_query($sql)) )
	{
		$sql_error = $db->sql_error();
		print 'Could not query attachment informations - SQL ERROR:<br />';
		print $sql_error['code'] . ": ". $sql_error['message']. "<br>\n";
		die('Executed SQL Statement: <br />' . $sql);
	}

	$row = $db->sql_fetchrow($result);

	if (intval($attach_config['allow_ftp_upload']))
	{
		$dest_file = THUMB_DIR . '/t_' . $row['physical_filename'];
	}
	else
	{
		$dest_file = $upload_dir . '/' . THUMB_DIR . '/t_' . $row['physical_filename'];
	}

	$source = $upload_dir . '/' . $row['physical_filename'];

	if (create_thumbnail($source, $dest_file, $row['mimetype']))
	{
		$update_ids[] = $row['attach_id'];
	}

	if (count($update_ids) > 0)
	{
		$sql = "UPDATE " . ATTACHMENTS_DESC_TABLE . " SET thumbnail = 1 WHERE attach_id IN (" . implode(', ', $update_ids) . ")";

		if ( !($result = $db->sql_query($sql)) )
		{
			$sql_error = $db->sql_error();
			print 'Could not query attachment informations - SQL ERROR:<br />';
			print $sql_error['code'] . ": ". $sql_error['message']. "<br>\n";
			die('Executed SQL Statement: <br />' . $sql);
		}
	}
}

if ( ($migrate_manual) || ($migrate_auto) )
{
	$sql = "SELECT * FROM " . ATTACHMENTS_DESC_TABLE . "
	WHERE (thumbnail = 0) AND (mimetype LIKE '%image%')
	LIMIT 100";

	if ( !($result = $db->sql_query($sql)) )
	{
		$sql_error = $db->sql_error();
		print 'Could not query attachment informations - SQL ERROR:<br />';
		print $sql_error['code'] . ": ". $sql_error['message']. "<br>\n";
		die('Executed SQL Statement: <br />' . $sql);
	}

	$update_ids = array();

	if ($db->sql_numrows($result) == 0)
	{
		die('Nothing more to convert.');
	}

	while ($row = $db->sql_fetchrow($result))
	{
		if (intval($attach_config['allow_ftp_upload']))
		{
			$dest_file = THUMB_DIR . '/t_' . $row['physical_filename'];
		}
		else
		{
			$dest_file = $upload_dir . '/' . THUMB_DIR . '/t_' . $row['physical_filename'];
		}

		if ( ($migrate_manual) )
		{
			echo '<br /><a href="download.php?id=' . $row['attach_id'] . '" target="_blank">Review the Attachment: ' . $row['real_filename'] . '</a>&nbsp; -- &nbsp;<a href="create_thumbnails.php?migrate_manual=1&create_thumbnail=' . $row['attach_id'] . '">Create Thumbnail</a><br />';
		}
		else if ( $migrate_auto )
		{
			$source = $upload_dir . '/' . $row['physical_filename'];

			if (create_thumbnail($source, $dest_file, $row['mimetype']))
			{
				echo "<br />Created Thumbnail from: " . $row['real_filename'];
				$update_ids[] = $row['attach_id'];
			}
		}
	}

	if (count($update_ids) > 0)
	{
		$sql = "UPDATE " . ATTACHMENTS_DESC_TABLE . " SET thumbnail = 1 WHERE attach_id IN (" . implode(', ', $update_ids) . ")";

		if ( !($result = $db->sql_query($sql)) )
		{
			$sql_error = $db->sql_error();
			print 'Could not query attachment informations - SQL ERROR:<br />';
			print $sql_error['code'] . ": ". $sql_error['message']. "<br>\n";
			die('Executed SQL Statement: <br />' . $sql);
		}
	}

	if ($total > 100)
	{
		echo "<br /><br />Now 100 from " . $total . " Thumbnails are created. Please hit the refresh button to create the next 100 thumbnails.<br />";
	}
	else
	{
		echo "<br /><br />FINISHED.<br />";
	}
}

?>

This version of /scripts/create_thumbnails.php was protected from running on any Attachment mod that wasn't 2.3.x. To enable it to work on 2.4.x, find this code near the top of the file:

Code: Select all

if ( (!defined('ATTACH_VERSION')) || ( (!strstr(ATTACH_VERSION, '2.3.')) ) ) 
{ 
   message_die(GENERAL_MESSAGE, 'Only Version 2.3.x supported.'); 
} 
and replace it with this:

Code: Select all

if ( (!defined('ATTACH_VERSION')) || ( (!strstr(ATTACH_VERSION, '2.4.')) ) ) 
{ 
   message_die(GENERAL_MESSAGE, 'Only Version 2.4.x supported.'); 
} 
Remember, back up your site before trying this!

janmartin
Registered User
Posts: 1
Joined: Wed Oct 19, 2005 6:59 pm
Location: Luton

works

Post by janmartin » Mon Apr 03, 2006 9:34 am

Just to confirm, that at least the manual option still works for:
phpBB 2.0.19 with
Attachment Mod Version 2.4.1

I just used it for 28 old .jpg attachments.

Automatic failed because the sript needs to run longer than 30 seconds and thats not permitted at my host.

Also one gets an error message, just ignore it:
Warning: Missing argument 1 for get_supported_image_types() in /whatever/me/public/myforum/attach_mod/includes/functions_thumbs.php on line 70


My settings at Extensions Special Categories:
Display Images Inlined No
Create Thumbnail Yes
Minimum Thumbnail Filesize 12000
Make use of GD2 Extension Yes
Imagick Program (Complete Path) empty
Maximum Image Dimensions 0x0
Image Link Dimensions 600x600
Search Imagick clicked
Test Settings clicked

Even after clicking "Search Imagick" the Imagick Program (Complete Path) is empty?

But it works anyway.

Great file. Should be part of the Attachment Mod and integrated into Control Panel.

Don't forget to delete it after you are finished!

Post Reply

Return to “[2.0.x] MODs in Development”