PDA

View Full Version : Server-side Thumbnailed Attachments


CVMagic
28 Dec 2003, 07:17
Thumbnailed Attachments Version 1.0

Description: Its kind of Self explanitory, but in anycase if you dont know what it does, it checks if an attached image is larger than your specified size and if it is it will use ImageMagick, Netpbm, or the GD Image functions to resize it accourdingly using a rather simple formula to make sure the thumbnails are kept in scale.

Usual Mod Warning: This moddification unlike most other thumbnailed attachment mods isn't only a template hack so mind you, you'd have to make sure you backup your files before using this hack.

Screenshots/Test Threads: I have one included below and this link contains a vB that has already been modded: http://www.cheatandwin.com/forums/showthread.php?s=&threadid=216. But i should let you know that both are kind of outdated already since i did update the instructions from an oversight i had made earlier..

Requirements: Umm, as vB goes i'd say you'd need 2.2.x or higher but i designed it under 2.3.3 so there might be slight differences namely in the templates but not much to worry about that..
PHP 4.0.6 <- For the moment that is the minimum requirement for the modifications i have made aside to the ones required for vB
Any of the following 3: ImageMagick, Netpbm, or GD 2.01 or higher

Thats about it, any comments, suggestions, or questions feel free to post here or even email me personally at cvmagic at cheatandwin dot com.

[edit]
New Updated Version Download Today!

Shell Geeks
28 Dec 2003, 09:49
intresting hack, but in your sample forum, some of the desktop photos didn't resize and they scroll hella far to the right. I might install this later today.

MindTrix
28 Dec 2003, 10:17
Nice idea although i believe something similar has been done. Ill be sure too check this out later, Thanks

CVMagic
28 Dec 2003, 10:54
@Shell Geeks:
actually in that demo i took an exsisting thread, and for a while the users thought that the attachments didnt work, so they posted with image tags, look at the source if you want..

@MindTrix:
I do hope not, lol when i started the hack earlier today or yesterday im not sure lol, i did a simple search for this hack and only could find the template versions of this hack( in the sence that they'd use the image tags to resize for them client side) or a gallery hack but not one that directly modified attachment.php to generate the thumbs

MindTrix
28 Dec 2003, 11:23
In which case it hasnt been made then, so Congrats!!!

Im also guessing this is your first hack here at vb.org so congratulations on that also, hope to see more from you :)

Long Live vB2!!!

Dean C
28 Dec 2003, 12:03
Looks good - I know a client of mine was looking for this so thanks ;)

chrisvonc
28 Dec 2003, 14:56
Hmm.. nice, I will try this on my test forum. How will yours handle images smaller than the values you set up? The thumbnail hack I use now wont ignore smaller images sizes and will resize them up to the set values.

Just as a FYI, there are 2 other "thumbnailing" hacks, one as you pointed out is template, the other is vbcode.
http://www.vbulletin.org/forum/showthread.php?t=52685
http://www.vbulletin.org/forum/showthread.php?s=&threadid=52344

Chris :)

gmarik
28 Dec 2003, 17:47
still doen't get what it is, what's for rour XP screenshot?

CVMagic
28 Dec 2003, 19:50
@gmarik:
Well the screenshot shows a thumb that was created from a 1280 x 780 image, I needed to pick something that most people would think was big.

@chrisvonc:
Yes, smaller images arent resized they are in actuality are the original image, so needing to load the GD libraries is not required.

@MindTrix:
^_^ yes it is my 1st hack, i wanted my first post to be one

Slynderdale
29 Dec 2003, 10:00
Is there a way to cache the thumbnail? Your current method isn't effiecent. If the forum has alot of image attachments, this hack could bog down the server because it would have to dynamicly create the thumbnail each time the page loads. Also I looked at the code, if the thread has quite a few images atatched, it will greatly increase the page load time because it generated each thumbnail and uses resampling which isn't the fastest method but the best quality method.

This hack is great for small forums, but larger ones that have alot of attached images would see a performance decrease if they have alot of page views.

CVMagic
29 Dec 2003, 16:00
Is there a way to cache the thumbnail? Your current method isn't effiecent. If the forum has alot of image attachments, this hack could bog down the server because it would have to dynamicly create the thumbnail each time the page loads. Also I looked at the code, if the thread has quite a few images atatched, it will greatly increase the page load time because it generated each thumbnail and uses resampling which isn't the fastest method but the best quality method.

This hack is great for small forums, but larger ones that have alot of attached images would see a performance decrease if they have alot of page views. actually slynderdale thats what im doing now, im coding that and along with a CP frontend, the only trouble is that im trying to avoid extra database queries than i have to so im trying to think of a method to allow some sort of cacheing, either by creating a temp folder where all the thumbnails would be stored and looked up for, or create a new database table to contain all the thumbnails which would be processed when you post the attachment rather than when viewing it...

CVMagic
30 Dec 2003, 03:31
I dont mean to double post, but since no one has replied yet i have to,... I actually got the requested cache in place and options added in the Admin panel under options so you wont need to edit attachments.php everytime you want to change thumbnail sizes or change cache directories, i have included updated instructions, and im planning to add upgrade instructions just incase( i doubt you'd need it tho because its all simple enough )...

[File Updated, Please download it again if you have downloaded it already]

FleaBag
31 Dec 2003, 16:50
Excellent hack, just what I was looking for to be honest. A lot of my users like to post photographs of themselves and gigs they've been to, only trouble is my forum has an 800 pixel width, which always gets shunted around when people post large images. This is ideal. :D

Thanks!

CVMagic
31 Dec 2003, 20:41
^_^ thanks, if your all interested im soon going to take this hack and add it support to scott's filebased attachements then officially release it, because it seems from all the forum versions i've tested it with its been rather flawless, and when it hasnt it were mainly due to permission issues on setting up the directories, lol yeah i dont follow my own instructions :-P

aliencode
31 Dec 2003, 22:10
Any chance of getting Image Magick support for this great hack?

CVMagic
31 Dec 2003, 22:34
Sure, ill add that to my todo list

aliencode
01 Jan 2004, 18:51
That would be great CVMagic - Im running 3 gamma now and I know it has integrated thumbnailing of attachments but GD is limited to certain filetypes. ImageMagick supports almost all image formats, plus its much easier to install for those of us with our own servers. Much appreciated I like your clean mod.

CVMagic
01 Jan 2004, 20:35
by the way as for ImageMagick intergration do you perfer just running direct exec commands or having ImageMagick Commands intergraded into php? I much Perfer the intergraded ones over exec ones because of security reasons and the fact that some servers disallow exec commands but the thing about intergraded ones for php is that you have to rebuild your server, so ill code it accourding to what you think is best in this case.

aliencode
01 Jan 2004, 20:56
Either way would be fine I would imagine, vbulletin is commercial product that is normally run on a dedicated server anyways. I personally have written most of my thumbnailing scripts using the system commands, ya know adding both types wouldnt really be hard since the system commands are one line using convert program.

CVMagic
02 Jan 2004, 10:27
^_^ okay im done, i just added support for No Imaging for those people who wanted to add this hack and planning to move to a new server that has GD or otherwise soon, Netpbm Support which i frankly like better than both GD and ImageMagick, ImageMagick Support for those people who want it :-D, GD2 was there already but now i have function verification so you wont get those nasty errors if lets say you dont have 2.0.1 or higher installed, and i made sure that scott's attachments as files hack wont interfere, as a side note when scott released that he was still a genious since i still dont have to modify any of his code to make this hack to work which may i say i was happy about....
So overall the requirements needed now to run this hack now are none, the requirements are set to whatever functions you have set to work rather than just GD...
Oh and i also made sure that possible security holes are covered to avoid someone sneaking in a abritary command when converting ;)...
It will be posted on the 1st post as an attachment, enjoy :)

aliencode
02 Jan 2004, 17:07
CVMagic - excellent hack - this is how hacks should be made, clean simple, not much modification. Thank you kindly!

AutomatikStudio
02 Jan 2004, 21:54
Hmm...well I added the script but I'm getting broken images now and when you click on the broken thumbnail image it takes you to the real picture.

CVMagic
03 Jan 2004, 01:49
that is odd, can you add '&dl=1' to the attachment url and post the results of the error..

CVMagic
04 Jan 2004, 03:15
Okay, I debugged the issue, and it was a simple error in my part that my version of php for windows didnt pick up which i odd i must say so here is the simple fix


-----------
find
-----------
if($dc=0){

-----------
Replace with
-----------
if(!($dc==1)){

###########

Done ^_^

It has already been applied to the 1.5 version so all is well, and thank you for pointing the error out AutomatikStudio

tcs
09 Jan 2004, 02:27
Nice hack, however I have a problem. I set the max size of an image to 200x200 and the size to 1 mb. I try to upload a file that is 500x400 and vb warns that the image is too big to upload. (Exceeds the 200x200 I set)

I am on VB 2.3.3
I have no other hacks installed in the attachments.php
I ran the Sql quarries and verified there existence in the db
I triple checked the php additions
I have disable GD 2+ and tried enabled as well
I set the imagemagak 2 1 and have the exact path.


It is making a image to the thumbs folder but not the size I told it to. "150x150"
If I up the size of my image allowance it uploads the image and does say "Click here to enlarge" but the image in the thread is the same size as the attached image in the thread.

Hope I explained this well enough. Let me knoe if not.

Chuck

pigsy
12 Jan 2004, 19:59
Had some problems getting this to work.

The problems I've encountered were:

1. The main problem is because it resizes on the fly when a page loads. If you're applying to this hack to a busy site, you can sometimes as we do have 5+ images in a thread. Although it seems to work when there's just one image, any more and it seems like the script doesn't have long enough to complete the conversion and you end up with broken images, and corrupt files in the thumbs dir. Is there any way to give the script time to generate the thumbnails. Alternatively if a script could be created to convert all images store in the directory in one hit, might take some time, but its where you'll eventually end up - and I think it can cope with converting one image on a thread as a new post is made.

2. ImageMagick worked in that it created a resized thumbnail but for some reason it generated the name without quotes - but the script is expecting those since it uses the php function escapeshellarg for the filename. Anyone know a way round this?

3. Couldn't get NetPBM to reduce the image size, it simply created a copy of the oversized image to display.

Great hack, and potentially what I've been looking for - but unworkable on my forum unfortunately. Any assistance much appreciated.

CVMagic
27 Jan 2004, 16:04
:-P what can i say, sorry about the delay... i should note that with safemode this hack does not run well at all, I didnt code it with making it safemode compatible in mind at all..., but as in multiple images at a time, it should work just fine because w/o safemode the images have all the time in the world to complie its thumbnails and plus if a user were to press stop it still continues on its own(again not safe mode compatible)... but noted i was using a much older version of netphm and imagemagick so it might not work as i intended at all, but dont worry at all im working on a newversion that instead of processing the attachment on post view it will do it during the post thus be safemode compatible in a sence...

CVMagic
27 Jan 2004, 16:10
Nice hack, however I have a problem. I set the max size of an image to 200x200 and the size to 1 mb. I try to upload a file that is 500x400 and vb warns that the image is too big to upload. (Exceeds the 200x200 I set)

I am on VB 2.3.3
I have no other hacks installed in the attachments.php
I ran the Sql quarries and verified there existence in the db
I triple checked the php additions
I have disable GD 2+ and tried enabled as well
I set the imagemagak 2 1 and have the exact path.


It is making a image to the thumbs folder but not the size I told it to. "150x150"
If I up the size of my image allowance it uploads the image and does say "Click here to enlarge" but the image in the thread is the same size as the attached image in the thread.

Hope I explained this well enough. Let me knoe if not.

Chuck

Well Chuck it seems that you had two problems that were not related to this hack at all, the size limit that you set it to limit the size of the upload itself not the thumb so if you upload 500x400 image it might just have been way too big for your settings to allow, now as for the 150x150 image there could be 2 problems, one you have GD disabled or php does not see it at all so it just lets the image pass on because it has nothing else it can do, or the image your uploading itself is smaller than 150x150

FeKuLa
29 Jan 2004, 08:39
Can you help me CVMagic?

In my forum, I obtain any broken thumbnails, look:

http://www.indicedivx.com/foro/showthread.php?s=&threadid=24416

OR

http://www.indicedivx.com/foro/showthread.php?s=&threadid=23930

(You need register for show thumbs. Login: testing, pass: testing)

Thanks

CVMagic
29 Jan 2004, 09:18
I've PMed you on your site already with the name: CVMagic, but in anycase if you have blocked out PMs, there might be 2 issues one that the file was somehow interupted during thumbnail generation which your solution would to be just deleting all the thumbs and let the script generate all the thumbs again, if its the second issue til this day gets me which is the your using GD2 it as some problem with some gif files and wont allow it to go beyond reading it at all which then i'd just either recommend disabling gif file uploading or getting Imagemagick or Netphm with gif/jpeg/jpeg2000/png support and using them as your method to thumbnail images...

[edit] There is another method too, actually its a work around if you dont want to install those other 2 programs, it means that those bad gif files will go unresized but hey its alot better than an X no? well here is the code you need to replace:

}
else
{
imagedestory($simg);
$dc=0;
}
}

Replace that with:

}
else
{
if(function_exists(imagedestory)){
imagedestory($simg);
}
$dc=0;
}
}

tcs
29 Jan 2004, 12:58
Thanks for the reply. I have tried many different settings to no avail. I am of the opinion there is a server issue with imagemagik and GD. Don't know what it is yet.

Thanks for the reply...

memobug
30 Jan 2004, 07:59
Will this be ported to vB3? I will be your dearest friend. Well, not quite that dear!

Regards,

Matt

FeKuLa
30 Jan 2004, 18:46
Thank you CVMagic, my problem is solved :)

CVMagic
31 Jan 2004, 05:28
@tcs:
Can you try out one of the attachments and add &dl=1 to the url address and tell me what error it says, it might be a simple error that i could fix for you...
@memobug:
I believe vB3 has it built in but ill take a look at it and make it so, just as long as there is a demand for it

memobug
31 Jan 2004, 08:44
Hi CVMagic,

The resizing of image attachments to conform to max pixel sizes is not built in to vB3. What is integrated is a thumbnailing feature that will take your attachment (whatever size it is) and produce a thumbnail image that can be used for inline display (default is 100pix) - linked to the original, unresized image.

vB3 does not manipulate images to conform to max size standards. If size checking is enabled, it will simply say the image is too large.

For those others who have asked about having an auto-size feature, it was recommended at Vbulletin.com that a hack be requested at Vbulletin.org. I have seen a few requests already for avatar and profile picture resizing on this forum, too, so I am sure there is a demand for autosizing.

Best,

Matt

pigsy
01 Feb 2004, 17:47
Hi CVMagic,

Many thanks for your feedback. Regarding safemode, I don't actually have this turned on and I don't have a particularly short timeout for scripts because some of the ones I run last 60 secs. Can you point me in the direction of any apache/php/linux settings that might give rise to problems when processing multiple images - and end up with broken images.

I feel there's still hope for me, if I could just figure what's wrong. Nice work all the same.

mskgr
06 Feb 2004, 22:17
Fatal error: imagecreatetruecolor(): requires GD 2.0 or later in /var/www/html/myphone/forum/attachment.php on line 199


Well, I have to say that $ImageMagick_enabled=1; and my path for imagekick is OK ('/usr/X11R6/bin/'), as I already use it for photopost.

So, what's wrong :)

mskgr
06 Feb 2004, 22:42
Now I get strange errors... Somethign changed but I don't know what :)


<br>
<b>Warning</b>: stat failed for ./thumbs/'claudia.jpg'.tmp.155 (errno=2 - No such file or directory) in <b>/var/www/html/myphone/forum/attachment.php</b> on line <b>174</b><br>
<br>
<b>Warning</b>: Cannot add header information - headers already sent by (output started at /var/www/html/myphone/forum/attachment.php:174) in <b>/var/www/html/myphone/forum/attachment.php</b> on line <b>174</b><br>
<br>
<b>Warning</b>: fopen("./thumbs/'claudia.jpg'.tmp.155", "rb") - No such file or directory in <b>/var/www/html/myphone/forum/attachment.php</b> on line <b>175</b><br>
<br>
<b>Warning</b>: Supplied argument is not a valid File-Handle resource in <b>/var/www/html/myphone/forum/attachment.php</b> on line <b>176</b><br>
<br>
<b>Warning</b>: Supplied argument is not a valid File-Handle resource in <b>/var/www/html/myphone/forum/attachment.php</b> on line <b>177</b><br>



And yes, there is a thumbs directory on my forum path. And it's changed to 777, and guess what I see .tmp files in there :)

CVMagic
07 Feb 2004, 03:49
Fatal error: imagecreatetruecolor(): requires GD 2.0 or later in /var/www/html/myphone/forum/attachment.php on line 199


Well, I have to say that $ImageMagick_enabled=1; and my path for imagekick is OK ('/usr/X11R6/bin/'), as I already use it for photopost.

So, what's wrong :)
That might just mean that ImageMagick was not setup correctly so i skips over to the next thing which is GD, and seeing that your the rare few with GD 2.0 it passed the function checks but still you get that error.

CVMagic
07 Feb 2004, 03:51
Now I get strange errors... Somethign changed but I don't know what :)


<br>
<b>Warning</b>: stat failed for ./thumbs/'claudia.jpg'.tmp.155 (errno=2 - No such file or directory) in <b>/var/www/html/myphone/forum/attachment.php</b> on line <b>174</b><br>
<br>
<b>Warning</b>: Cannot add header information - headers already sent by (output started at /var/www/html/myphone/forum/attachment.php:174) in <b>/var/www/html/myphone/forum/attachment.php</b> on line <b>174</b><br>
<br>
<b>Warning</b>: fopen("./thumbs/'claudia.jpg'.tmp.155", "rb") - No such file or directory in <b>/var/www/html/myphone/forum/attachment.php</b> on line <b>175</b><br>
<br>
<b>Warning</b>: Supplied argument is not a valid File-Handle resource in <b>/var/www/html/myphone/forum/attachment.php</b> on line <b>176</b><br>
<br>
<b>Warning</b>: Supplied argument is not a valid File-Handle resource in <b>/var/www/html/myphone/forum/attachment.php</b> on line <b>177</b><br>



And yes, there is a thumbs directory on my forum path. And it's changed to 777, and guess what I see .tmp files in there :)


You have the safemode problem, but give me a link ill look into it directly for you.

mskgr
07 Feb 2004, 04:14
@CVMagic:

Try this one :)

http://www.myphone.gr/forum/attachment.php?postid=204433&dl=1

pigsy
08 Feb 2004, 21:46
Hi CVMagic, can you elaborate on the safemode problem - are you referring to the php setting, because if so - I don't have this turned on, yet still have a problem processing multiple images on a thread. Hopefully you can point me in the right direction, thanks.