相关疑难解决方法(0)

如何为imagecolorallocate提供颜色?

我有一个PHP变量,其中包含有关颜色的信息.例如$text_color = "ff90f3".现在我想给这个颜色imagecolorallocate.这样的imagecolorallocate作品:

imagecolorallocate($im, 0xFF, 0xFF, 0xFF);

所以,我试图做以下事情:

$r_bg = bin2hex("0x".substr($text_color,0,2));
$g_bg = bin2hex("0x".substr($text_color,2,2));
$b_bg = bin2hex("0x".substr($text_color,4,2));
$bg_col = imagecolorallocate($image, $r_bg, $g_bg, $b_bg);
Run Code Online (Sandbox Code Playgroud)

这是行不通的.为什么?我也尝试了没有bin2hex,它也没有用.任何人都可以帮助我吗?

php string hex colors

7
推荐指数
2
解决办法
8127
查看次数

用想象力环绕形象

尝试拍摄矩形照片,将其裁剪成方形区域,然后将其遮盖成具有透明背景的圆形.

//$dims is an array with the width, height, x, y of the region in the rectangular image (whose path on disk is $tempfile)

$circle = new \Imagick();
$circle->newImage($dims['w'], $dims['h'], 'none');
$circle->setimageformat('png');
$circle->setimagematte(true);
$draw = new \ImagickDraw();
$draw->setfillcolor('#ffffff');
$draw->circle($dims['w']/2, $dims['h']/2, $dims['w']/2, $dims['w']);
$circle->drawimage($draw);

$imagick = new \Imagick();
$imagick->readImage($tempfile);
$imagick->setImageFormat( "png" );
$imagick->setimagematte(true);
$imagick->cropimage($dims['w'], $dims['h'], $dims['x'], $dims['y']);
$imagick->compositeimage($circle, \Imagick::COMPOSITE_DSTIN, 0, 0);
$imagick->writeImage($tempfile);
$imagick->destroy();
Run Code Online (Sandbox Code Playgroud)

结果是矩形图像,未被切割并且没有被环化.我究竟做错了什么?

示例图片: 在此输入图像描述

$ dims的示例输入= {"x":253,"y":0,"x2":438.5,"y2":185.5,"w":185.5,"h":185.5}

粗略的预期产量:

在此输入图像描述

图像我看起来大致像输入图像.

php imagick

0
推荐指数
1
解决办法
8297
查看次数

标签 统计

php ×2

colors ×1

hex ×1

imagick ×1

string ×1