Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.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
在wordpress的PHP GD库中合并两个图像时,不会显示该图像_Php_Wordpress_Gdlib_Imagecreatefrompng - Fatal编程技术网

在wordpress的PHP GD库中合并两个图像时,不会显示该图像

在wordpress的PHP GD库中合并两个图像时,不会显示该图像,php,wordpress,gdlib,imagecreatefrompng,Php,Wordpress,Gdlib,Imagecreatefrompng,我得到了这个代码工作,但几周后,代码不工作,我试图看看哪里的错误来自,但我不知道。 我确实使用GD库创建了图像,并且创建成功,但当我想将其与另一张图片合并时,它只显示黑屏。请了解如何解决此问题。以下是我的代码: 请注意,图像已成功创建并保存,因此create_image()函数没有问题 function create_image() { $cer_id = get_the_ID(); $cer_org_nummer = get_field('orgnummer_dqm');

我得到了这个代码工作,但几周后,代码不工作,我试图看看哪里的错误来自,但我不知道。 我确实使用GD库创建了图像,并且创建成功,但当我想将其与另一张图片合并时,它只显示黑屏。请了解如何解决此问题。以下是我的代码: 请注意,图像已成功创建并保存,因此create_image()函数没有问题

function create_image()
{
    $cer_id = get_the_ID();
    $cer_org_nummer = get_field('orgnummer_dqm');
    $cer_today = date('Y-m-d');
    $cer_org_name = get_field('foretags_namn_dqm');
    $cer_org_date = $cer_org_nummer . ' | ' . $cer_today;


    $im = @imagecreate(500, 450);
    $yellow = imagecolorallocate($im, 255, 255, 255);  // yellow
    imagecolortransparent($im, $yellow);

    $black = imagecolorallocate($im, 252, 195, 91);
    $string = "Digital Quality Managment";
    $font = FUNC_PLUGIN_D_DQM . '/font/Roboto-Regular.ttf';// black

    /*    imagestring($im, $font, 50, 300, $string, $black);*/
    /*    imagestring($im, $font, 3, 300, $cer_org_name, $black);*/
    /*    imagestring($im, $font, 0, 10, $cer_org_date, $black);*/
    imagettftext($im, 35, 0, 60, 270, $black, $font, 'CERTIFIED');

    imagettftext($im, 25, 0, 0, 320, $black, $font, $cer_org_date);

    imagepng($im, "wp-content/plugins/certificates/cer_images/image_$cer_id.png");
    imagedestroy($im);
}
      create_image();
    $image1 = "wp-content/plugins/certificates/cer_images/dqm_png_logo.png";
    $image2 = "wp-content/plugins/certificates/cer_images/image_$cer_id.png";

    list($width, $height) = getimagesize($image2);


    $image1 = imagecreatefromstring(file_get_contents($image1));

    $image2 = imagecreatefromstring(file_get_contents($image2));


    imagealphablending($image1, FALSE);
    imagesavealpha($image1, TRUE);
    imagecopymerge($image1, $image2, 110, 50, 0, 0, $width, $height, 100);


    header("Content-type: image/png");
    imagepng($image1);
    imagedestroy($image1);

请尝试下面的代码

这个代码对我有用

$pro_directory_path = get_attached_file( get_post_thumbnail_id($_REQUEST['apid']),'full' );

$mainmetadata = wp_get_attachment_metadata( get_post_thumbnail_id( $_REQUEST['apid'] ) );

$pro_img_name = $mainmetadata['file'];

$pro_img_name_extra = '1'.$mainmetadata['file'];

// $val_id is id of image(bigger image/background Image)
$directory_path = get_attached_file( $val_id,'full' );

$metadata = wp_get_attachment_metadata( $val_id );

$name = $metadata['file'];

$bgFile = $directory_path;

// We want our final image to be 76x76 size
//user $metadata to get ordiginal height width of image
// $value contain height width of wall mentioned by admin
$x = $metadata['width'];
$y = $metadata['height'];

$x_inch = $metadata['width']/96;
$y_inch = $metadata['height']/96;

$width_proption = $wall_w_inch/$x_inch;
$height_proption = $wall_h_inch/$y_inch;

$img_pos_x = ($x/2)-($resizedwidth/2);
$img_pos_y = ($y/2)-($resizedheight);

/* Code to generate custom wall images - STart */
$inn_width = ($innerimg_width / $width_proption) * 12 ;
$inn_height = ($innerimg_height / $height_proption) * 12 ;

$resizedFilename = get_template_directory().'/woocommerce/temp_images/cust_'.$pro_img_name;

$img_url_extra =  get_stylesheet_directory_uri().'/woocommerce/temp_images/cust_'.$pro_img_name;

//function to resize Artist product image in desired size's (Variation sizes).
$imgData = resize_image($pro_directory_path, $inn_width, $inn_height);
imagepng($imgData, $resizedFilename);

list($resizedwidth, $resizedheight) = getimagesize($resizedFilename);

/* Code to generate custom wall images - ENDS */

$imageFile = $resizedFilename;

// dimensions of the final image
$final_img = imagecreatetruecolor($x, $y);

// Create our image resources from the files
$image_1 = imagecreatefrompng($bgFile);
$image_2 = imagecreatefrompng($imageFile);

// Enable blend mode and save full alpha channel
imagealphablending($final_img, true);
imagesavealpha($final_img, true);

// Copy our image onto our $final_img
imagecopy($final_img, $image_1, 0, 0, 0, 0, $x, $y);
imagecopy($final_img, $image_2, $img_pos_x, $img_pos_y, 0, 0, $resizedwidth, $resizedheight);

ob_start();
$path =  __DIR__ .'/custom_wall_img/'.$name;
imagepng($final_img,$path);
$watermarkedImg = ob_get_contents(); // Capture the output
ob_end_clean(); // Clear the output buffer

嗨,我还使用了相同类型的代码来合并2个图像,在我这方面效果很好。我用了4个多月的代码。。。如果你愿意,我会和你分享我的代码谢谢,请和我分享@YogeshGargHI@AmjadKhalil请检查答案部分添加的代码。。这里$\u请求['apid']是id映像。您需要使用映像的目录路径来实现此功能。@YogeshGarg谢谢,但这不起作用,我想主题可能有问题,因为我的代码在几天前就可以工作,但在更新主题后就开始不起作用了。好的。。那么请检查一下你的代码。。如果你需要帮助,请告诉我。