Bom, com a dica do Robra, pude realizar a alteração, que é muito simples (com o código já feito) dentro do
function_upload.php, dentro da pasta
include.
Só copiar e substituir o código que, por padrão, só faz o encaixe da imagem de acordo com os pixels que vc determina no fórum. Com a alteração adquirida pelo usuário do phpBB, pode-se realizar o resize da imagem enviada e funciona perfeitamente.
Estou muito satisfeito.
O que não pude testar, até o momento, é se os GIFs animados, após dado o RESIZE da imagem ,apartir do código implementado, funcionaria. Bom, nao funciona mesmo, se voce nao especificar o patch do ImageMagik. E é por isso que nao pude testar esse lance, ainda.
No mais, o código se mantem preciso e funcional.
Vou postar aqui o conteúdo do código. Para interesse dos outros.
Código: Selecionar todos
##############################################################
## Título do MOD: Resize sent avatars
## Autor do MOD: Hołek < holek@toolserver.org > (Michał Połtyn) http://toolserver.org/~holek/
## Descrição: Você não está cansado dos erros que o phpBB apresenta quando
## tenta fazer o upload de um novo avatar por causa de seus pixels?
## Por quê o phpBB não o redimensiona por ele mesmo?
## Mas agora pode! Mesmo que o tamanho da imagem exceda o limite
## estabelecido pelo fórum, o phpBB vai automaticamente realizar o upload
## e redimensionar seu avatar com sucesso!!!
## MOD Version: 1.1.1
##
## Nível de Instalação: Fácil
## Tempo de instalação: 1 minuto
## Arquivos para editar: includes/functions_upload.php
## Arquivos incluidos: nenhum.
## Licensa: 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
##
##############################################################
## ANTES DE FAZER ESTA ALTERAÇÃO, RECOMENDAMOS QUE FAÇÃ O BACKUP DO SEU FÓRUM.
##############################################################
#
#----[ ABRA ]-----------------------------------------------------------
#
includes/function_upload.php
#
#----[ ENCONTRE ]-----------------------------------------------------------
#
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;
}
#
#----[ SUBSTITUA POR ]---------------------------------------------------
#
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 );
}
#
#-----[ SALVE/FECHE TODOS OS ARQUIVOS ]------------------------------------------
#
# EoM
Funcionou bem, para mim.
Também há uma alteração a ser realizada, vista por outro usuário em outro fórum.
Bem, este, diz que o
aspect ratio da imagem se danifica um pouco, então ele apresentou estas novas linhas de comando, para substituir (na anteriormente postada) o
function create_thumb.
Código: Selecionar todos
function create_thumb()
{
global $config;
if ($this->width > $this->height)
{
// need to calculate aspect ratio of this image
$aspectRatio = $this->width / $this->height;
$thumb_width = $this->upload->max_width;
$thumb_height = $thumb_width / $aspectRatio;
}
else if ($this->width height)
{
$aspectRatio = $this->height / $this->width;
$thumb_height = $this->upload->max_height;
$thumb_width = $thumb_height / $aspectRatio;
// check if thumb width is larger than max_width because if it is it will break layout
if($thumb_width > $this->upload->max_width){
$thumb_width = $this->upload->max_width;
$thumb_height = $thumb_width * $aspectRatio;
}
}
Este, particularmente, adicionei a alteração, mas nao vi nenhuma mudança notável. Mas, funcionando com essa alteração.
Então.. é isso.
Valeu mais uma vez,
robra.