用于PHP的imagecrop()替代方法5.5 [英] imagecrop() alternative for PHP < 5.5
本文介绍了用于PHP的imagecrop()替代方法5.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个出于好奇心而提出的简单问题,可能会有一个复杂的答案:是否可以通过结合其他GD函数来模仿5.4之类的早期PHP 5.5版本的新的imagecrop()?
A simple question motivated by a curiosity, with probably a complex answer: Is it possible to emulate the new PHP 5.5 imagecrop() in earlier versions, like 5.4, by combining other GD functions?
Awn ..但没有imagecrop()黑线错误,请. :p
Awn.. But without the imagecrop() black line bug, please. :p
推荐答案
这应该是imagecrop()
的替代品(没有bug ...):
This should be a drop-in replacement for imagecrop()
(without the bug...):
function mycrop($src, array $rect)
{
$dest = imagecreatetruecolor($rect['width'], $rect['height']);
imagecopy(
$dest,
$src,
0,
0,
$rect['x'],
$rect['y'],
$rect['width'],
$rect['height']
);
return $dest;
}
用法:
$img = mycrop($img, ['x' => 10, 'y' => 10, 'width' => 100, 'height' => 100]);
请注意,该错误显然已在 PHP 5.6.12 中修复.
Note that the bug is apparently fixed in PHP 5.6.12.
这篇关于用于PHP的imagecrop()替代方法5.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文