Serpent писал(а):
Не, кто-то обещал помочь с кодами. Я-то свой выложил!
Код, правда, сама не писала. Поставила бесплатную галерею сразу со всеми вкусностями. Потому что замучалась повторять то, что там уже есть и хорошо работает. Может, тебе ее сюда прикрутить и тоже радоваться жизни? Так вот там - такой кусок:
Код:
$filename = basename($path);
$dirname = dirname($path);
// extension of the picture filename
$extension = get_extension($filename);
if (in_array($extension, array('jpg', 'JPG', 'jpeg', 'JPEG')))
{
$srcImage = @imagecreatefromjpeg($path);
}
else if ($extension == 'png' or $extension == 'PNG')
{
$srcImage = @imagecreatefrompng($path);
}
else
{
unset($extension);
}
if ( isset( $srcImage ) )
{
// width/height
$srcWidth = imagesx( $srcImage );
$srcHeight = imagesy( $srcImage );
$ratioWidth = $srcWidth/$newWidth;
$ratioHeight = $srcHeight/$newHeight;
// maximal size exceeded ?
if ( ( $ratioWidth > 1 ) or ( $ratioHeight > 1 ) )
{
if ( $ratioWidth < $ratioHeight)
{
$destWidth = $srcWidth/$ratioHeight;
$destHeight = $newHeight;
}
else
{
$destWidth = $newWidth;
$destHeight = $srcHeight/$ratioWidth;
}
}
else
{
$destWidth = $srcWidth;
$destHeight = $srcHeight;
}
// according to the GD version installed on the server
if ( $_POST['gd'] == 2 )
{
// GD 2.0 or more recent -> good results (but slower)
$destImage = imagecreatetruecolor( $destWidth, $destHeight);
imagecopyresampled( $destImage, $srcImage, 0, 0, 0, 0,
$destWidth,$destHeight,$srcWidth,$srcHeight );
}
else
{
// GD prior to version 2 -> pretty bad results :-/ (but fast)
$destImage = imagecreate( $destWidth, $destHeight);
imagecopyresized( $destImage, $srcImage, 0, 0, 0, 0,
$destWidth,$destHeight,$srcWidth,$srcHeight );
}
if (($tndir = mkget_thumbnail_dir($dirname, $page['errors'])) == false)
{
return false;
}
$dest_file = $tndir.'/'.$conf['prefix_thumbnail'];
$dest_file.= get_filename_wo_extension($filename);
$dest_file.= '.'.$tn_ext;
// creation and backup of final picture
if (!is_writable($tndir))
{
array_push($page['errors'], '['.$tndir.'] : '.l10n('no_write_access'));
return false;
}
imagejpeg($destImage, $dest_file);
// freeing memory ressources
imagedestroy( $srcImage );
imagedestroy( $destImage );
list($tn_width, $tn_height) = getimagesize($dest_file);
$tn_size = floor(filesize($dest_file) / 1024).' KB';
$info = array( 'path' => $path,
'tn_file' => $dest_file,
'tn_width' => $tn_width,
'tn_height' => $tn_height,
'tn_size' => $tn_size );
return $info;
}
// error
else
{
echo l10n('tn_no_support')." ";
if ( isset( $extenstion ) )
{
echo l10n('tn_format').' '.$extension;
}
else
{
echo l10n('tn_thisformat');
}
exit();
}
}
$pictures = array();
$stats = array();
if (!function_exists('gd_info'))
{
array_push($page['errors'], l10n('GD library is missing'));
}
Если что, ссылка на то, как у меня -
http://photo-and-more.info/index.php?/category/26
А официальный сайт разработчиков этого чуда -
http://www.phpwebgallery.net/