Php 为Imagick中图像上的注释文本添加背景
各位。我正在做一个关于在线照片编辑器的大学项目,但我在使用Imagick添加到图像上的文本中添加背景色时遇到了一些问题。下面是用于Imagick的php代码 caption.phpPhp 为Imagick中图像上的注释文本添加背景,php,image,imagick,caption,annotate,Php,Image,Imagick,Caption,Annotate,各位。我正在做一个关于在线照片编辑器的大学项目,但我在使用Imagick添加到图像上的文本中添加背景色时遇到了一些问题。下面是用于Imagick的php代码 caption.php <?php $caption = $_POST['caption']; $caption_color = $_POST['caption_color']; $caption_color = "#".$caption_color; $font = $_POST['font']; $image = new
<?php
$caption = $_POST['caption'];
$caption_color = $_POST['caption_color'];
$caption_color = "#".$caption_color;
$font = $_POST['font'];
$image = new Imagick();
$draw = new ImagickDraw();
$data = "\intermediate.jpg";
$im = new Imagick(__DIR__.$data);
$im->setImageFormat("jpg");
$draw->setFillColor($caption_color);
$draw->setFont('Arial');
$draw->setFontSize( $font );
$im->annotateImage($draw, $im->getImageWidth()/2, $im->getImageHeight()/2, 0, $caption);
header('Content-type: image/jpg');
$im->writeImages(__DIR__.$data, true);
驻留在effect.php中的html部分
function myCaptionAjax() {
var loader = $("#ajax-loader");
var div_loader = $("#img");
$.ajax({
type: 'POST',
url: 'effects/caption.php',
data: {caption: $('#caption_value').val(),caption_color: $('#caption_color').val(),font: $('#font_value').val()},
beforeSend: function () {
loader.show();
div_loader.hide();
},
success: function ( data ) {
loader.hide();
div_loader.show();
display();
},
error: function ( xhr ) {
alert( "error" );
}
});
};
Caption:<input type="textarea" rows="4" cols="10" maxlength="40" id="caption_value" />
<input id="caption_color" class="jscolor" value="ab2567">
<input type="range" min="10" max="50" value="10" step="1" onchange="showFont(this.value)" id="font_value"/> <span id="rangeFont"></span>
<button class="button" onclick="myCaptionAjax()">Apply</button>
标题:
申请
非常感谢您的帮助 不要使用注释图像
取而代之的是在ImagickDraw对象中绘制文本,然后使用Imagick::drawImage在图像上合成文本,如本例所示:我自己解决了这个问题,不过感谢您的建议。我将记住drawImage()函数,以便以后使用。