Unofficial modifications
nieoficjalne modyfikacje for?w phpBB by Przemo

Modyfikacje mniejsze - [Album] Automatyczna zmiana rozmiaru zdj?? przy wysy?aniu

kidzior - Wto 26 Cze, 2007
Temat postu: [Album] Automatyczna zmiana rozmiaru zdj?? przy wysy?aniu
Modyfikacja ma za zadanie zmian? rozmiaru zdj?? wysy?anych do Albumu na Forum.

Mo?na ustawi? maksymalne wymiary zdj?cia (domy?lnie wy??czone) oraz wag? zdj?cia (domy?lnie 1MB).

Zaczynamy:

Wiadomo?? ukryta / Hidden message
Aby zobaczy? wiadomo?? postaw piwo autorowi piwo.
Otw?rz:
album_upload.php

Znajd?:
Kod
if( ($filesize == 0) or ($filesize > $album_config['max_file_size']) )
{
message_die(GENERAL_MESSAGE, $lang['Bad_upload_file_size']);
}


Zamie? na:
Kod
if( ($filesize == 0) or ($filesize > 1024000) )
{
message_die(GENERAL_MESSAGE, $lang['Bad_upload_file_size']);
}
$recompress = 0;
if ($filesize > $album_config['max_file_size'])
{
$recompress = 1;
}


Znajd?:
Kod
if ( ($pic_width > $album_config['max_width']) or ($pic_height > $album_config['max_height']) )
{
@unlink(ALBUM_UPLOAD_PATH . $pic_filename);

if ($album_config['gd_version'] == 0)
{
@unlink(ALBUM_CACHE_PATH . $pic_thumbnail);
}

message_die(GENERAL_ERROR, $lang['Upload_image_size_too_big']);
}


Zamie? na:
Kod
if ( (($pic_width > $album_config['max_width']) or ($pic_height > $album_config['max_height'])) OR ($recompress == 1) )
{
if ($album_config['gd_version'] == 0)
{
@unlink(ALBUM_UPLOAD_PATH . $pic_filename);
@unlink(ALBUM_CACHE_PATH . $pic_thumbnail);
message_die(GENERAL_ERROR, $lang['Upload_image_size_too_big']." Error code: 001");
}
$gd_errored = FALSE;


switch ($pic_filetype)
{
case '.jpg':
$read_function = 'imagecreatefromjpeg';
break;
case '.png':
$read_function = 'imagecreatefrompng';
break;
}

$src = @$read_function(ALBUM_UPLOAD_PATH . $pic_filename);

if (!$src)
{
$gd_errored = TRUE;
$pic_thumbnail = '';
}

if (($pic_width > $album_config['max_width']) or ($pic_height > $album_config['max_height']))
{
if ($pic_width > $pic_height)
{
$new_width = $album_config['max_width'];
$new_height = $album_config['max_width'] * ($pic_height/$pic_width);
}
else
{
$new_height = $album_config['max_height'];
$new_width = $album_config['max_height'] * ($pic_width/$pic_height);
}
}
else
{
$new_width = $pic_width;
$new_height = $pic_height;

}
$new_pic = ($album_config['gd_version'] == 1) ? @imagecreate($new_width, $new_height) : @imagecreatetruecolor($new_width, $new_height);

$resize_function = ($album_config['gd_version'] == 1) ? 'imagecopyresized' : 'imagecopyresampled';

@$resize_function($new_pic, $src, 0, 0, 0, 0, $new_width, $new_height, $pic_width, $pic_height);


if (!$gd_errored)
{
// print $recompress ."<br>".$pic_filename; exit;
// overwrite old image
@unlink(ALBUM_UPLOAD_PATH . $pic_filename);

switch ($pic_filetype)
{
case '.jpg':
@imagejpeg($new_pic, ALBUM_UPLOAD_PATH . $pic_filename, 80);
break;
case '.png':
@imagepng($new_pic, ALBUM_UPLOAD_PATH . $pic_filename);
break;
}

@chmod(ALBUM_CACHE_PATH . $pic_thumbnail, 0777);
$pic_width = $new_width;
$pic_height = $new_height;
} // End IF $gd_errored
else
{
@unlink(ALBUM_UPLOAD_PATH . $pic_filename);

if ($album_config['gd_version'] == 0)
{
@unlink(ALBUM_CACHE_PATH . $pic_thumbnail);
}

message_die(GENERAL_ERROR, $lang['Upload_image_size_too_big']." Error code: 002");
}
}


Otw?rz:
lang_main_album.php

Dodaj na ko?cu (przed ?>):
Kod
$lang['Max_file_size'] = 'Maximum file size before recompression (bytes)';
$lang['Max_width'] = 'Maximum image width before recompression (pixel)';
$lang['Max_height'] = 'Maximum image height before recompression (pixel)';


Mo?liwe Errory to:
Error 1: Obrazek jest za du?y albo nie masz zainstalowanych bibliotek GD2.
Error 2: B??d w samym GD.

Powy?szych b??d?w jednak nigdy nie mia?em. :)


Powered by phpBB modified by Przemo © 2003 phpBB Group