Ask a Question related to PHP Notes, Design and Development.
-
nanobot@chipx86.com #1
note 33613 added to function.imagecopyresampled
imagecopyresampled will shrink an image smoothly, but if you try to use it to enlarge an image, the result will be blocky, like in imagecopyresized. The following function will enlarge an image more smoothly using bilinear resampling.
function imagecopyenlarged ( $dst_im , $src_im , $dstX , $dstY , $srcX , $srcY , $dstW , $dstH , $srcW , $srcH )
{
for ( $y = $dstY ; $y < $dstH ; $y ++ )
{
$tempy = ( $y - $dstY ) * $srcH / $dstH + $srcY;
$tempyd = $tempy - floor ( $tempy );
$tempyu = 1 - $tempyd;
$tempy = floor ( $tempy );
for ( $x = $dstX ; $x < $dstW ; $x ++ )
{
$tempx = ( $x - $dstX ) * $srcW / $dstW + $srcX;
$tempxr = $tempx - floor ( $tempx );
$tempxl = 1 - $tempxr;
$tempx = floor ( $tempx );
$tempq = imagecolorsforindex ( $src_im , imagecolorat ( $src_im , $tempx , $tempy ) );
$tempw = imagecolorsforindex ( $src_im , imagecolorat ( $src_im , $tempx + 1 , $tempy ) );
$tempa = imagecolorsforindex ( $src_im , imagecolorat ( $src_im , $tempx , $tempy + 1 ) );
$temps = imagecolorsforindex ( $src_im , imagecolorat ( $src_im , $tempx + 1 , $tempy + 1 ) );
$tempq['red'] = $tempq['red'] * $tempxl + $tempw['red'] * $tempxr;
$tempq['green'] = $tempq['green'] * $tempxl + $tempw['green'] * $tempxr;
$tempq['blue'] = $tempq['blue'] * $tempxl + $tempw['blue'] * $tempxr;
$tempa['red'] = $tempa['red'] * $tempxl + $temps['red'] * $tempxr;
$tempa['green'] = $tempa['green'] * $tempxl + $temps['green'] * $tempxr;
$tempa['blue'] = $tempa['blue'] * $tempxl + $temps['blue'] * $tempxr;
$tempq['red'] = $tempq['red'] * $tempyu + $tempa['red'] * $tempyd;
$tempq['green'] = $tempq['green'] * $tempyu + $tempa['green'] * $tempyd;
$tempq['blue'] = $tempq['blue'] * $tempyu + $tempa['blue'] * $tempyd;
imagesetpixel ( $dst_im , $x , $y , imagecolorallocate ( $dst_im , $tempq['red'] , $tempq['green'] , $tempq['blue'] ) );
}
}
}
Note that this function is only for enlarging an image. Depending on the application, you may need to have your script detect whether it will be enlarging or shrinking the image, and use the respective function.
----
Manual Page -- [url]http://www.php.net/manual/en/function.imagecopyresampled.php[/url]
Edit Note -- [url]http://master.php.net/manage/user-notes.php?action=edit+33613[/url]
Delete Note -- [url]http://master.php.net/manage/user-notes.php?action=delete+33613&report=yes[/url]
Reject Note -- [url]http://master.php.net/manage/user-notes.php?action=reject+33613&report=yes[/url]
nanobot@chipx86.com Guest
-
note 33827 added to function.function-exists
This can be used to conditionally define a user function. In this sense, it can act as a sort of inline include_once(). For example, suppose you... -
note 33730 added to function.min
Caution : it seems that min() can return a string : min(";",50)=";" (I expected zero) ---- Manual Page --... -
note 33714 added to function.register-tick-function
please can anyone help me to discover if this function can be used to make a chat ---- Manual Page --... -
note 33689 added to function.next
i was just looking around and saw this. i'd just like to say "huh" and be on my merry way. ok buh-bi. merry meet, rose love ---- Manual Page --... -
note 33575 added to function.register-shutdown-function
If your script exceeds the maximum execution time, and terminates thusly: Fatal error: Maximum execution time of 20 seconds exceeded in - on line...



Reply With Quote

