Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为Imagick中图像上的注释文本添加背景_Php_Image_Imagick_Caption_Annotate - Fatal编程技术网

Php 为Imagick中图像上的注释文本添加背景

Php 为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

各位。我正在做一个关于在线照片编辑器的大学项目,但我在使用Imagick添加到图像上的文本中添加背景色时遇到了一些问题。下面是用于Imagick的php代码

caption.php

<?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" />&nbsp;
    <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"/>&nbsp;<span id="rangeFont"></span>
    <button class="button" onclick="myCaptionAjax()">Apply</button>
标题:
申请

非常感谢您的帮助

不要使用注释图像


取而代之的是在ImagickDraw对象中绘制文本,然后使用Imagick::drawImage在图像上合成文本,如本例所示:

我自己解决了这个问题,不过感谢您的建议。我将记住drawImage()函数,以便以后使用。