note 109025 deleted from function.imagecopyresampled by danbrown
| From: | danbrown@php.net | Date: | Thu, 14 Jun 2012 15:25:48 +0000 |
| Subject: | note 109025 deleted from function.imagecopyresampled by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-188612@lists.php.net to get a copy of this message | ||
Note Submitter: tages at docsis dot ru
----
/*------------
СÑÑаниÑа â1
------------*/
//ÐпÑеделение Ñипа "ÑигÑÑÑ"
function ImageStatus($Width, $Height)
{
if ($Width > $Height)
return (int) 1;
if ($Width < $Height)
return (int) 2;
if ($Width == $Height)
return (int) 3;
return (int) -1;
}
//ÐпÑеделение опÑеÑаÑии
обÑезаниÑ, на оÑновании
Ñапов "ÑигÑÑ"
function OperationInImage($OrigiImageStatus, $NewImageStatus)
{
if (
($OrigiImageStatus == 1 AND $NewImageStatus == 2) OR
($OrigiImageStatus == 1 AND $NewImageStatus == 3) OR
($OrigiImageStatus == 3 AND $NewImageStatus == 2))
return (int) 1;
if (
($OrigiImageStatus == 2 AND $NewImageStatus == 1) OR
($OrigiImageStatus == 2 AND $NewImageStatus == 3) OR
($OrigiImageStatus == 3 AND $NewImageStatus == 1))
return (int) 2;
if (
($OrigiImageStatus == 1 AND $NewImageStatus == 1) OR
($OrigiImageStatus == 2 AND $NewImageStatus == 2))
return (int) 3;
return (int) -1;
}
//РаÑÑÐµÑ Ð¿Ð°ÑамеÑÑов Ð´Ð»Ð¸Ð½Ñ Ð¸
ÑиÑÐ¸Ð½Ñ Ð´Ð»Ñ Ð¿Ð¾Ð»ÑÑениÑ
ÑÑебÑемого иобÑажениÑ
function SizeCut($OrigiWidth, $OrigiHeight, $NewWidth, $NewHeight)
{
/* опÑеделÑем ÑигÑÑÑ
оÑигиналÑного изобÑÐ°Ð¶ÐµÐ½Ð¸Ñ */
$OrigiImageStatus = ImageStatus($OrigiWidth, $OrigiHeight);
/* опÑеделÑем ÑигÑÑÑ
ÑÑебÑемого изобÑÐ°Ð¶ÐµÐ½Ð¸Ñ */
$NewImageStatus = ImageStatus($NewWidth, $NewHeight);
// опÑеделÑем меÑод
обÑÐµÐ·Ð°Ð½Ð¸Ñ Ñой или иной
ÑÑоÑÐ¾Ð½Ñ Ð¸ ÑеализÑем его
switch (OperationInImage($OrigiImageStatus, $NewImageStatus))
{
case 1:
// ÐÑопоÑÑионалÑно $OrigiHeight
=$NewHeight
$OrigiWidthCut = ($OrigiHeight * $NewWidth) / $NewHeight; $OrigiHeightCut =
$OrigiHeight; break;
case 2:
//ÐÑопоÑÑионалÑно $OrigiWidth =$NewWidth
$OrigiHeightCut = ($OrigiWidth * $NewHeight) / $NewWidth; $OrigiWidthCut = $OrigiWidth;
break;
case 3:
//ÑÐ¸Ð¿Ñ ÑигÑÑ ÑавнÑ,
опÑеделÑем, где, ÑÑо можно
ÑÑезаÑÑ
$OrigiWidthCut = $OrigiWidth; $OrigiHeightCut = ($OrigiWidth * $NewHeight) / $NewWidth;
if ($OrigiHeightCut > $OrigiHeight)
{
$OrigiHeightCut = $OrigiHeight; $OrigiWidthCut = ($OrigiHeight * $NewWidth) /
$NewHeight;
}
break;
default:
//ÐÑоÑее (квадÑаÑ), без
изменений
$OrigiWidthCut = $OrigiWidth; $OrigiHeightCut = $OrigiHeight; break;
}
return array('width' => $OrigiWidthCut, 'height' => $OrigiHeightCut);
}