vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.0 Full Releases (https://vborg.vbsupport.ru/forumdisplay.php?f=33)
-   -   Auto Resize Image Attachments (Avatars & Profile Pic Too).... (https://vborg.vbsupport.ru/showthread.php?t=68429)

John_44 03-10-2005 02:39 PM

Ok, i played around with it. Please notice that i know nothing about PHP, but i was able to track down the Problem:

If i change:

if ($width_factor > $height_factor)
{
$nw = round($w / $width_factor);
$nh = round($h / $width_factor);
}

to:

if ($width_factor > $height_factor)
{
$nw = 400 ;
$nh = round($h / $width_factor);
}

it works. 500,600,1000 -> Anything bigger 400 don?t.
I guess that for some reasons ImeageCreateTrueColor don?t like big numbers.. but i have no Ideas why.
The image i used was a Standart jpg with 1600*1200. Size played no role.

I would really apreciate your help on this topic, as i will definitly extend this genius hack !

What i want to add:
-Other extension (.jpeg,.jpe ...)
-File size

Does anybody know if GDlib can read EXIF Data ?

(Yes my English sucks ;))

John_44 03-10-2005 02:52 PM

Sorry. It works with 450 and 500. But 600 is to mutch. This makes me sick.

(And it is not "ImageCopyResampled". The following line works just fine:

ImageCopyResampled($ni,$im,0,0,0,0,1000,$nh,$w,$h) ; )

John_44 03-10-2005 04:45 PM

If somebody else has the same Problem: As a workaround i use:

$width_factor = $w / 500;
$height_factor = $h / 500;
if ($width_factor > $height_factor)
{
$nw = round($w / $width_factor);
$nh = round($h / $width_factor);
}
else
{
$nw = round($w / $height_factor);
$nh = round($h / $height_factor);
}

$ni=imagecreatetruecolor($nw,$nh);
ImageCopyResampled($ni,$im,0,0,0,0,$nw,$nh,$w,$h);
UnsharpMask($ni);

John_44 03-10-2005 07:43 PM

And i found a Bug: If more than one Image is resized, the script returns an error 500. However the first one is still uploaded.

Anybody else with this error ?

nosaj 03-29-2005 02:02 AM

thanks mini2, installed and working on my vBulletin Version 3.0.7 Forum. :classic:

LiewCF 03-31-2005 06:20 PM

Great! this hack work for my bloggers forum. There is other similar hack too, but it does not work. :)

Thank you!

JohnBee 04-03-2005 10:09 AM

I started to install this hack on 3.0.3
but in the functions_file.php I could not find the section that says:

Code:

@unlink($attachment);
eval('$error = "' . fetch_phrase('attachbaddimensions', PHRASETYPEID_ERROR) . '";');
$errors[] = array(
        'filename' => $attachment_name,
        'error' => $error...

is there another portion of code I should look for?

Blam Forumz 04-18-2005 09:00 PM

for attachments is it possible for them to be clikabkle?

Harley D 04-25-2005 01:32 AM

Quote:

Originally Posted by mini2
No idea on the darker image, I cant reproduce the problem.

I have a PHP Store that has pic resizing, and I've found that gif, jpegs, and pngs.... one of those will darken when resized. try changing the type of file and upload it to see how it renders after being resized.

Harley D 04-25-2005 01:37 AM

Quote:

Originally Posted by Hexemer
Hello,

first, thank you for this nice hack. :)

But, I have a Problem. :disappointed: The uploaded picture is "darker" than the original one.

attachment 1: original
attachment 2: uploaded in my forums

gd version: 2.0.12

Can you help me? :ermm:


I did some more checking and found that .JPG will darken but .GIF doesn't.
So use paint shop or photo shop to change from a JPG to GIF, this should solve this problem. If it does, please post so other will know if it works.

Razasharp 05-07-2005 12:25 AM

Excellent hack! *clicks install* Does exactly what is says on the tin :-)

Just a quick question tho, do the 'original' large files automatically get deleted off the server or do we have to do that manually?

Also a note for people using the attachment resizer, you have to 'increase' the sizes in your ACP to let the larger files get uploaded to then be resized. :-)

Razasharp 05-18-2005 11:28 PM

Sometimes the images shown (JPG) are a bit dark... anyway to get them lighter? :-/

Most users wont know how to conver to gif, so thats not any option really...

Bounce 05-26-2005 06:06 PM

Uploaded all as per instructions,doesn't seem to be working

Do you need safe mode turned off for this to work...

Uploaded the 2 hacks,no errors or anything but doesn't work :ermm:

Edit: Got the avatar hack working,slight problem same as another user, the pic is slightly darker :rolleyes:

lionslair 06-30-2005 07:20 AM

Thanks for that wiked hack

kobescoresagain 07-31-2005 04:02 AM

anyone know if you can intergrate this into vb gallery?

kmike 08-05-2005 05:41 AM

Excellent hack.
I see a couple of small problems with it though:
  1. it doesn't handle additional image types supported by getimagesize() PHP function, e.g. .SWF, .PSD, and .BMP. First two are probably non-issue, but our forum has .bmp attachments enabled, and this hack will generate an empty resized image for them
  2. a huge image can cause "out of memory" PHP error on ImageCopyResampled() call, and the hack doesn't handle these situations (I think 500 errors cited in this thread are caused exactly by this - check your error logs for PHP errors)
  3. the attachment file size stored in the db is wrong - the stored number is the size of original attachment, not the resized one. the total space occupied by member's attachments will be wrong, which may cause problems if attachment quotas are defined for usergroups
  4. some memory could be freed during script execution by adding ImageDestroy() calls in the proper places
  5. I think UnsharpMask() call is only needed if the attachthumbs option in admin CP set to "Yes - sharpen" (to be consistent with thumbnails handling)
  6. there's no need to mess with "require_once('./includes/functions_image.php');" line at all. The file is only included once, if needed

I've fixed these problems, and also did some code cleanup.
You can uncomment error_log() lines and change email to your actual address to get some idea how this hack performs.

Code:

                                // HACK: auto resize uploaded images
                                switch ($imginfo[2])
                                {
                                case 1:
                                        $im = ImageCreateFromGIF($attachment);
                                        break;
                                case 2:
                                        $im = ImageCreateFromJPEG($attachment);
                                        break;
                                case 3:
                                        $im = ImageCreateFromPNG($attachment);
                                        break;
                                // no way to handle these image types
                                default:
                                        // error_log("Couldn't resize $attachment ($filesize bytes)", 1, "email@yourdomain.net");
                                        @unlink($attachment);
                                        eval('$error = "' . fetch_phrase('attachbaddimensions', PHRASETYPEID_ERROR) . '";');
                                        $errors[] = array(
                                                'filename' => $attachment_name,
                                                'error' => $error
                                        );
                                        return false;
                                }

                                $w = $imginfo[0];
                                $h = $imginfo[1];
                                $width_factor = $w / $maxattachwidth;
                                $height_factor = $h / $maxattachheight;
                                if ($width_factor > $height_factor)
                                {
                                        $nw = round($w / $wdth_factor);
                                        $nh = round($h / $wdth_factor);
                                }
                                else
                                {
                                        $nw = round($w / $height_factor);
                                        $nh = round($h / $height_factor);
                                }

                                $ni = @ImageCreateTrueColor($nw, $nh);
                                if ($ni OR !@ImageCopyResampled($ni, $im, 0, 0, 0, 0, $nw, $nh, $w, $h))
                                {
                                        // failed to resize this image
                                        // error_log("Couldn't resize $attachment ${w}x${h} to ${nw}x${nh} ($filesize bytes)", 1, "email@yourdomain.net");
                                        @unlink($attachment);
                                        eval('$error = "' . fetch_phrase('attachbaddimensions', PHRASETYPEID_ERROR) . '";');
                                        $errors[] = array(
                                                'filename' => $attachment_name,
                                                'error' => $error
                                        );
                                        return false;
                                }
                                @ImageDestroy($im);
                                if (PHP_VERSION != '4.3.2' AND $vboptions['attachthumbs'] == 2)
                                {
                                        require_once('./includes/functions_image.php');
                                        UnsharpMask($ni);
                                }
                                switch ($imginfo[2])
                                {
                                case 1:
                                        @ImageGIF($ni, $attachment);
                                        break;
                                case 2:
                                        @ImageJPEG($ni, $attachment, 70);
                                        break;
                                case 3:
                                        @ImagePNG($ni, $attachment);
                                        break;
                                }
                                @ImageDestroy($ni);
                                $filesize1 = @filesize($attachment);
                                // error_log("Resized $attachment ${w}x${h} to ${nw}x${nh} ($filesize to ${filesize1})", 1, "email@yourdomain.net");
                                $filesize = $filesize1;
                                // /HACK


mvigod 08-08-2005 12:41 AM

kmike,

nice fixes. has anyone tested this yet on 3.5 RC2?

thephonemall 08-31-2005 02:51 PM

I am getting this error when attempting the Profile Pic modification:

Fatal error: Call to undefined function: unsharpmask() in /home/website/forums/includes/functions_upload.php on line 294

EDIT:

Nevermind added
require_once('./includes/functions_image.php');
and it works!

MrNase 10-25-2005 12:39 PM

Can this one please be ported to vB3.5? :)

lazytown 11-14-2005 08:41 AM

A port to 3.5 would be VERY useful.

wildondallas 11-26-2005 05:36 AM

Quote:

Originally Posted by mvigod
has anyone tested this yet on 3.5 RC2?

I have tested this hack (Geek Auto Avatar Resizer)with the 3.5.1 upgrade, and its working perfectly so far. Only tested with IE though...See my post and screenshots here: https://vborg.vbsupport.ru/showthrea...196#post831196

ConqSoft 11-26-2005 05:53 AM

As I noted in the other thread, 3.5.x has built in Avatar and Profile Pic resizing, so these hacks are now obsolete. ;)

ConqSoft 11-26-2005 05:54 AM

As I noted in the other thread, 3.5.x has built in Avatar and Profile Pic resizing, so these hacks are now obsolete. ;)

sgtmaj 01-17-2006 12:55 AM

Quote:

Originally Posted by ConqSoft
As I noted in the other thread, 3.5.x has built in Avatar and Profile Pic resizing, so these hacks are now obsolete. ;)

not obsolete for resizing attachments......and I for one would like to see it modified for 3.5.xxx

sgtmaj 01-22-2006 12:57 AM

I still have yet to find a hack that will automatically resize attachments for version 3.5.xxx.

Anyone know of one out there????

Raydar 02-06-2006 04:59 PM

Hi,

Can this hack also be used for VB 3.5.3?

Thanks

Reg

mrcake 01-12-2009 02:41 AM

It's gone. :(
Anybody know if there is a new one that resizes automatically? users are whining... lol


All times are GMT. The time now is 04:53 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01397 seconds
  • Memory Usage 1,815KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (27)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete