|
@@ -104,21 +104,42 @@ trait Fill
|
|
|
imagefilledpolygon($img, $values2, 3, $color);
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 缩放图片Logo
|
|
|
+ * @param type $im 资源
|
|
|
+ * @param type $maxWidth 最大宽度
|
|
|
+ * @param type $maxHeight 最大高度
|
|
|
+ * @return type
|
|
|
+ */
|
|
|
+ public function resizeLogo($im, $maxWidth, $maxHeight) {
|
|
|
+ $picWidth = imagesx($im);
|
|
|
+ $picHeight = imagesy($im);
|
|
|
+ $newIM = imagecreatetruecolor($maxWidth, $maxHeight);
|
|
|
+
|
|
|
|
|
|
+ $almostBlack = imagecolorallocate($newIM,254,254,254);
|
|
|
+ imagefill($newIM,0,0, $almostBlack);
|
|
|
+ imagecolortransparent($newIM, $almostBlack);
|
|
|
+
|
|
|
+ ImageCopyResampled($newIM, $im, 0, 0, 0, 0, $maxWidth, $maxHeight, $picWidth, $picHeight);
|
|
|
+ imagedestroy($im);
|
|
|
+
|
|
|
+ return $newIM;
|
|
|
+ }
|
|
|
/**
|
|
|
* 缩放图片
|
|
|
- * @param type $im
|
|
|
- * @param type $maxwidth
|
|
|
- * @param type $maxheight
|
|
|
+ * @param type $im 资源
|
|
|
+ * @param type $maxWidth 最大宽度
|
|
|
+ * @param type $maxHeight 最大高度
|
|
|
* @return type
|
|
|
*/
|
|
|
- public function resizeImage($im, $maxwidth, $maxheight)
|
|
|
+ public function resizeImage($im, $maxWidth, $maxHeight)
|
|
|
{
|
|
|
$picWidth = imagesx($im);
|
|
|
$picHeight = imagesy($im);
|
|
|
+ $newIM = imagecreatetruecolor($maxWidth, $maxHeight);
|
|
|
|
|
|
- $newIM = imagecreatetruecolor($maxwidth, $maxheight);
|
|
|
- ImageCopyResampled($newIM, $im, 0, 0, 0, 0, $maxwidth, $maxheight, $picWidth, $picHeight);
|
|
|
+ ImageCopyResampled($newIM, $im, 0, 0, 0, 0, $maxWidth, $maxHeight, $picWidth, $picHeight);
|
|
|
imagedestroy($im);
|
|
|
|
|
|
return $newIM;
|
|
@@ -200,13 +221,14 @@ trait Fill
|
|
|
* 通过图片资源生成
|
|
|
* @param resource $im 图片资源
|
|
|
* @param resource $logoRes Logo资源
|
|
|
+ * @param int $stroke 是否对logo进行描边
|
|
|
* @return resource
|
|
|
*/
|
|
|
public function imageAddLogoRes($im, $logoRes, $stroke = 0) {
|
|
|
//计算宽和高
|
|
|
$w = imagesx($im);
|
|
|
$h = imagesy($im);
|
|
|
- $logoRes = $this->resizeImage($logoRes, min(36, $w / 5), min(36, $h / 5));
|
|
|
+ $logoRes = $this->resizeLogo($logoRes, max(36, $w / 6), max(36, $h / 6));
|
|
|
$srcWidth = imagesx($logoRes);
|
|
|
$srcHeight = imagesy($logoRes);
|
|
|
if($stroke) {
|