Page 6 of 9

Re: Attached Images Resizer, Converter & File Size Reducer

Posted: Thu Jan 08, 2015 2:31 pm
by HiFiKabin
:o well, they say you learn something new every day, and this is mine.

Members of my wifes forum are totally incapable of resizing images. I wish I had known that phpBB did it (if I set it correctly that is)

Thanks Martti

Re: Attached Images Resizer, Converter & File Size Reducer

Posted: Thu Jan 08, 2015 3:00 pm
by DavidIQ
martti wrote:It does reduce the filesize of course. But checking the maximum filesize is against the original filesize. Here is room for improvement I think. Example: you want to allow pdf's up to 1M but images up to 10M (they get downsized client side anyway when you set maximum dimensions.)
Good. I think you've reduced the amount of work I'd need to do! :mrgreen: Looks like the only thing left to do would be to somehow reduce the file size before or during upload since a file can meet the dimensions requirements but exceed the file size requirements. I can see now why you suggested client-side file resizing but doing this might be a bit more complicated than needed and might require the use of unwanted libraries possibly in undesirable formats (flash).

Re: Attached Images Resizer, Converter & File Size Reducer

Posted: Thu Jan 08, 2015 4:20 pm
by martti
I've submitted an improvement request in the issue tracker to make it clear in the ACP that client side resizing takes place when exceding dimensions.
https://tracker.phpbb.com/browse/PHPBB3-13481

And also an improvement request to handle file size for images differently.
https://tracker.phpbb.com/browse/PHPBB3-13482

Note: in some rare cases it's possible the client resize fails due to not enough memory. It would be good in this cases to reject the image based on either file size or dimension size (maybe the latest is built in. I did not check.)

Re: Attached Images Resizer, Converter & File Size Reducer

Posted: Fri Jan 30, 2015 11:42 am
by phpnewbtard
deleted

Re: Attached Images Resizer, Converter & File Size Reducer

Posted: Fri Jan 30, 2015 11:53 am
by ][Moon][Shine][
@phpnewbtard, nice! This may be an easy quick & dirty fix to the problem, something to look into. I am still not using phpBB, because it causes me more headaches to figure out conversion from Vanilla, but it's definitely something I'll keep an eye on.

Re: Attached Images Resizer, Converter & File Size Reducer

Posted: Fri Jan 30, 2015 12:07 pm
by phpnewbtard
deleted

Re: Attached Images Resizer, Converter & File Size Reducer

Posted: Fri Jan 30, 2015 12:14 pm
by phpnewbtard
deleted

Re: Attached Images Resizer, Converter & File Size Reducer

Posted: Tue Feb 10, 2015 3:06 am
by CtopherMI
I have wanted this mod/functionality for years (been a phpBB user since 2001), and always wondered why it wasn't part of the original attachment mod. With facebook making it so easy for people to upload huge image files right from their phones and tablets they want the same functionality on our forums!

When browsing forums was done from a PC where people had image editing capabilities I could see the argument that we just needed to explain to them how to edit their photos to a smaller size, I could get about half of my users to do it, at best. As more of my users browsed our forum from their phones they stopped coming. Facebook and other forums allowed them to take pictures and upload them to those other places without ANY editing. So what happened? We lost users. Period. And after seeing time and again that the developers here were ignoring this simple request I gave up thinking it would ever happen. Sure, we still have the forum going, and have some regular users, but nothing like the hundreds of active users on at all times of day and night. When I ask them why they weren't coming back, again and again it is because facebook and other forums allow them to upload any picture they want, directly, without having to go to photobucket first, or have to edit the images to make them smaller. My MAX file size is set at 1MB. Most users still couldn't do it, even though we all know a 100kb file is more than enough for a forum post, and now that they aren't on pcs they really don't care to even do it, or learn how to do it. We need this mod.

Okay, thanks for the chance to hear me out. About once a year I search for this mod, am always curious as to why it isn't there yet, and am thrilled that the discussion has come up again.

Keep up with the times or die - facebook is stealing phpBB traffic and this is part of the reason.

Re: Attached Images Resizer, Converter & File Size Reducer

Posted: Tue Feb 10, 2015 3:48 pm
by dan filipi
Agreed.

Before I did the MOD to 3.0, users had so much trouble it was rediculous.
Now I have it so image uploads are automatically resized even if the image is 5 mb and larger and big enough resolution to fill a billboard!
A 5 mb file gets resized on the server end to a very small fraction of the original and still looks very good.
The capability should have been built into 3.1 to keep up with the times.

Re: Attached Images Resizer, Converter & File Size Reducer

Posted: Tue Feb 10, 2015 3:56 pm
by DavidIQ
dan filipi wrote:Agreed.

Before I did the MOD to 3.0, users had so much trouble it was rediculous.
Now I have it so image uploads are automatically resized even if the image is 5 mb and larger and big enough resolution to fill a billboard!
A 5 mb file gets resized on the server end to a very small fraction of the original and still looks very good.
The capability should have been built into 3.1 to keep up with the times.
I'm curious...do you administer (configure, maintain, etc.) the actual server the forum is on as well?

Re: Attached Images Resizer, Converter & File Size Reducer

Posted: Tue Feb 10, 2015 4:49 pm
by dan filipi
DavidIQ wrote:
dan filipi wrote:Agreed.

Before I did the MOD to 3.0, users had so much trouble it was rediculous.
Now I have it so image uploads are automatically resized even if the image is 5 mb and larger and big enough resolution to fill a billboard!
A 5 mb file gets resized on the server end to a very small fraction of the original and still looks very good.
The capability should have been built into 3.1 to keep up with the times.
I'm curious...do you administer (configure, maintain, etc.) the actual server the forum is on as well?
Yes

Re: Attached Images Resizer, Converter & File Size Reducer

Posted: Tue Feb 10, 2015 5:08 pm
by DavidIQ
dan filipi wrote:
DavidIQ wrote:
dan filipi wrote:Agreed.

Before I did the MOD to 3.0, users had so much trouble it was rediculous.
Now I have it so image uploads are automatically resized even if the image is 5 mb and larger and big enough resolution to fill a billboard!
A 5 mb file gets resized on the server end to a very small fraction of the original and still looks very good.
The capability should have been built into 3.1 to keep up with the times.
I'm curious...do you administer (configure, maintain, etc.) the actual server the forum is on as well?
Yes
That's what I figured. The modification you're referencing will timeout on most servers without modifying script timeout value as well as max_upload_file_size. These can sometimes be overridden through .htaccess but not always. We see this happen with plupload in 3.1 as well which tries to resize images in much the same way.

Re: Attached Images Resizer, Converter & File Size Reducer

Posted: Tue Feb 10, 2015 5:23 pm
by dan filipi
Yes, root php.ini edits were needed which were made on the shared host as well as the vps we are on now.
If a shared host isn't willing to make those edits then it's time to move to a different host, this shouldn't be a reason to not have the feature.

Re: Attached Images Resizer, Converter & File Size Reducer

Posted: Tue Feb 10, 2015 5:50 pm
by DavidIQ
As I and others have said the feature is there in 3.1 through plupload. ;) Obviously won't make a difference for 3.0.

Re: Attached Images Resizer, Converter & File Size Reducer

Posted: Tue Feb 10, 2015 9:28 pm
by Volksdevil
DavidIQ wrote:the feature is there in 3.1 through plupload. ;)
So the building blocks are there but yet nobody has taken it on as a standalone extension for posts. :cry: I've implemented a button on the posting screen (Leads to a resizer hosted by myself) which at least allows members to resize their images, save, upload. But obviously that's not as smooth as it could be.

I also run a script that auto resizes avatars, so maybe that could be useful. Although it's probably old code these days...Works flawlessly though!

Code: Select all

## MOD Title: Resize sent avatars
## MOD Author: Hołek < holek@toolserver.org > (Michał Połtyn) http://toolserver.org/~holek/
## MOD Description: Aren't you tired of phpBB giving you dimension errors every time
## you upload new avatar? Why can't it resize the avatar on its own?
## Now it can! As long as the filesize is not exceeded,
## phpBB will upload and resize the file successfully.
## MOD Version: 1.1.1
## 
## Installation Level: Easy
## Installation Time: 1 minute
## Files To Edit: includes/functions_upload.php
## Included Files: 
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2
##############################################################
## MOD History:
## 
## 2009-10-18 - Version 1.1.1
## - fixed minor bug, causing wrong resizing method
## to be applied to pallette-based images
## (thanks to autinhyeu)
## 2009-10-18 - Version 1.1.0
## - support for animated GIFs
## - using Imagemagick if available
## 2009-10-17 - Version 1.0.0
## 
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
##############################################################

#
#----[ OPEN ]-----------------------------------------------------------
#

includes/function_upload.php

#
#----[ FIND ]-----------------------------------------------------------
#

if (!$this->upload->valid_dimensions($this))
{
$this->error[] = sprintf($user->lang[$this->upload->error_prefix . 'WRONG_SIZE'], $this->upload->min_width, $this->upload->min_height, $this->upload->max_width, $this->upload->max_height, $this->width, $this->height);
return false;
}

return true;
}

#
#----[ REPLACE WITH ]---------------------------------------------------
#

if (!$this->upload->valid_dimensions($this))
{
$valid = $this->create_thumb();

if (!$valid)
{
$this->error[] = sprintf($user->lang[$this->upload->error_prefix . 'WRONG_SIZE'], $this->upload->min_width, $this->upload->min_height, $this->upload->max_width, $this->upload->max_height, $this->width, $this->height);

return false;
}
}

return true;
}

/**
* Create a thumb if uploaded image is too big.
* This function was based mainly on MediaWiki's thumbnail creating process
* and create_thumbnail function in functions_posting.php
* @source MediaWiki
*/
function create_thumb()
{
global $config;

if ($this->width > $this->height) 
{
$thumb_width = $this->upload->max_width;
$thumb_height = $this->height*($this->upload->max_height/$this->width);
}
else if ($this->width < $this->height) 
{
$thumb_width = $this->width*($this->upload->max_width/$this->height);
$thumb_height = $this->upload->max_height;
}
else /* $this->width == $this->height */
{
$thumb_width = $this->upload->max_width;
$thumb_height = $this->upload->max_height;
}

// Only use imagemagick if defined and the passthru function not disabled
if ($config['img_imagick'] && function_exists('passthru'))
{
$quality = '';
$sharpen = '';
$frame = '';
$animation = '';
if ( $this->mimetype == 'image/jpeg' )
{
$quality = '-quality 80'; // 80%
/** Reduction in linear dimensions below which sharpening will be enabled */
if ( ( $thumb_width + $thumb_height ) / ( $this->width + $this->height ) < 0.85 )
{
$sharpen = '-sharpen 0x0.4';
}
}
elseif ($this->mimetype == 'image/png')
{
$quality = '-quality 95'; // zlib 9, adaptive filtering
}
elseif ($this->mimetype == 'image/gif')
{
/**
* Force thumbnailing of animated GIFs above this size to a single
* frame instead of an animated thumbnail. ImageMagick seems to
* get real unhappy and doesn't play well with resource limits. :P
* Defaulting to 1 megapixel (1000x1000)
*/
if($this->width * $this->height > 1.0e6)
{
// Extract initial frame only
$frame = '[0]';
}
else
{
// Coalesce is needed to scale animated GIFs properly (MediaWiki bug 1017).
$animation = ' -coalesce ';
}
}
# Specify white background color, will be used for transparent images
# in Internet Explorer/Windows instead of default black.

# Note, we specify "-size {$this->width}" and NOT "-size {$this->width}x{$this->height}".
# It seems that ImageMagick has a bug wherein it produces thumbnails of
# the wrong size in the second case.

if (substr($config['img_imagick'], -1) !== '/')
{
$config['img_imagick'] .= '/';
}
$cmd = 
escapeshellcmd($config['img_imagick']) . 'convert' . ((defined('PHP_OS') && preg_match('#^win#i', PHP_OS)) ? '.exe' : '') .
" {$quality} -background white -size {$this->width} ".
escapeshellarg($this->destination_file . $frame) .
$animation .
// For the -resize option a "!" is needed to force exact size,
// or ImageMagick may decide your ratio is wrong and slice off
// a pixel.
' -thumbnail ' . escapeshellarg( "{$thumb_width}x{$thumb_height}!" ) .
" -depth 8 $sharpen " .
escapeshellarg($this->destination_file) . ' 2>&1';

@passthru($cmd);

// after converting let's check the file dimensions again
if (($this->image_info = @getimagesize($this->destination_file)) !== false)
{
$this->width = $this->image_info[0]; // the _real_ width
$this->height = $this->image_info[1]; // the _real_ height
if ($this->upload->valid_dimensions($this)) 
{
return true;
}
}
}
if (extension_loaded('gd'))
{
/* This code is greatly based on MediaWiki's thumbnail generation process */
$typemap = array(
'image/gif' => array( 'imagecreatefromgif', 'palette', 'imagegif' ),
'image/jpeg' => array( 'imagecreatefromjpeg', 'truecolor', array( __CLASS__, 'imagejpegwrapper' ) ),
'image/png' => array( 'imagecreatefrompng', 'bits', 'imagepng' ),
'image/vnd.wap.wbmp' => array( 'imagecreatefromwbmp', 'palette', 'imagewbmp' ),
'image/xbm' => array( 'imagecreatefromxbm', 'palette', 'imagexbm' ),
);
if (!isset( $typemap[$this->mimetype] ))
{
return false;
}

list($loader, $color_style, $save_type) = $typemap[$this->mimetype];

if (!function_exists($loader))
{
return false;
}
$src_image = call_user_func( $loader, $this->destination_file );
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);

// Initialise the destination image to transparent instead of
// the default solid black, to support PNG and GIF transparency nicely
$background = imagecolorallocate( $thumb, 0, 0, 0 );
imagecolortransparent( $thumb, $background );
imagealphablending( $thumb, false );

if( $color_style == 'palette' ) {
// Don't resample for paletted GIF images.
// It may just uglify them, and completely breaks transparency.
imagecopyresized( $thumb, $src_image,
0,0,0,0,
$thumb_width, $thumb_height, $this->width, $this->height );
} else {
imagecopyresampled( $thumb, $src_image,
0,0,0,0,
$thumb_width, $thumb_height, $this->width, $this->height );
}

imagesavealpha( $thumb, true );

call_user_func( $save_type, $thumb, $this->destination_file );
imagedestroy($thumb);
imagedestroy($src_image);
$this->width = $thumb_width;
$this->height = $thumb_height;
return true;
}
return false;
}

static function imagejpegwrapper( $dst_image, $thumb_path ) {
imageinterlace( $dst_image );
imagejpeg( $dst_image, $thumb_path, 95 );
}

#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM