我正在开发图像编辑器,我成功地在位置x,y上的图像上写文字,现在我需要在被称为白色的图像上绘制白色图像。白色图像将绘制在位置线X,线Y和图像宽度,高度的动态大小。我写代码,但我没有得到图像的右坐标和高度宽度。 这是我的图像渲染功能。
$image = new Imagick('image.jpg');
$diagnose=$this->input->post('diagnoses');
$fontsize=$this->input->post('fontsize');
$fontstyle=$this->input->post('fontstyle');
$cordX = $this->input->post('posX');
$cordY = $this->input->post('posY');
$font_size = 20;
// Watermark text
//$diagnose = "Hello world.{newline}It's a beautiful day.";
$textlinesArray = explode("{newline}",$diagnose);
// Create a new drawing palette
$draw = new ImagickDraw();
// Set font properties
$draw->setFont('Arial');
$draw->setFontSize($font_size);
$draw->setFillColor('black');
// Position text at the bottom-right of the image
$draw->setGravity(Imagick::GRAVITY_NORTHWEST);
$i = 0;
foreach ($textlinesArray as $index => $text) {
$newY = ($i * $font_size) + $cordY;
//echo $newY . "</br>";
//echo $text;
// Draw text on the image
$image->annotateImage($draw, $cordX, $newY,0, $text);
$i++;
}
$draw->setFillColor('magenta'); // Set up some colors to use for fill and outline
$draw->setStrokeColor( new ImagickPixel( 'cyan' ) );
$draw->setStrokeWidth(2);
$draw->rectangle($cordX, $cordY, 200, 300); // Draw the rectangle
$image->drawImage( $draw );
// Set output image format
$image->setImageFormat('png');
// Output the new image
header('Content-type: image/png');
echo $image;
这里是输出,我需要颜色框动态宽度高度和位置