
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
Good. I think you've reduced the amount of work I'd need to do!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.)
I'm curious...do you administer (configure, maintain, etc.) the actual server the forum is on as well?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.
YesDavidIQ wrote:I'm curious...do you administer (configure, maintain, etc.) the actual server the forum is on as well?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.
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.dan filipi wrote:YesDavidIQ wrote:I'm curious...do you administer (configure, maintain, etc.) the actual server the forum is on as well?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.
So the building blocks are there but yet nobody has taken it on as a standalone extension for posts.DavidIQ wrote:the feature is there in 3.1 through plupload.![]()
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
Users browsing this forum: Froddelaar and 6 guests