繁体   English   中英

PHP GD库-显示图像

[英]PHP GD Library - Display images

我只想在图像上显示另一个图像。

我已经写了信息,我想显示他的头像。

它是编写的HTML元素。 如何告诉服务器这是一个映像?

<?php

header('Content-Type: image/png');

$jpg_image = imagecreatefrompng('sign/sign.png');

$white = imagecolorallocate($jpg_image, 255, 255, 255);

$font_path = 'sign/font.ttf';

$posts = "424";

$followers = "2424";

$following = "41241241";

$image = "<img src='https://scontent.cdninstagram.com/t51.2885-19/s320x320/14719833_310540259320655_1605122788543168512_a.jpg'>";

$image2 = imagejpeg($image);


imagettftext($jpg_image, 50, 0, 170, 240, $white, $font_path, $posts);

imagettftext($jpg_image, 50, 0, 800, 240, $white, $font_path, $followers);

imagejpeg($jpg_image, 0, 1130, 240, $image, $white);

imagettftext($jpg_image, 50, 0, 1630, 240, $white, $font_path, $following);


imagepng($jpg_image);

imagedestroy($jpg_image);
?> 

如何使用imagecreatefromstring和file_get_contents获取图像?

<?php 

    // https://stackoverflow.com/questions/44593897/php-gd-library-display-images 
    header('Content-Type: image/png');

    $jpg_image = imagecreatefrompng('./sign/sign.png');

    $white = imagecolorallocate($jpg_image, 0, 0, 0);

    $font_path =  dirname(__FILE__) . '/sign/arial.ttf';

    $posts = "424";
    $followers = "2424";
    $following = "41241241";

    //$image = "<img src='https://scontent.cdninstagram.com/t51.2885-19/s320x320/14719833_310540259320655_1605122788543168512_a.jpg'>";

    // Load image from URL and Overlay Image
    $image = imagecreatefromstring(file_get_contents('https://scontent.cdninstagram.com/t51.2885-19/s320x320/14719833_310540259320655_1605122788543168512_a.jpg'));
    imagecopymerge($jpg_image, $image, 0, 0, 0, 0, 280, 280, 100); 

    // Write Text to image
    imagettftext($jpg_image, 25, 0, 50, 400, $white, $font_path, $posts);
    imagettftext($jpg_image, 24, 0, 225, 400, $white, $font_path, $followers);
    imagettftext($jpg_image, 24, 0,450, 400, $white, $font_path, $following);

    // Resize image
    $new_image = imagecreatetruecolor(500, 300);
    imagecopyresized($new_image, $jpg_image,0, 0, 0, 0, 500, 300,1006, 608);

    imagejpeg($new_image);

    imagedestroy($new_image);
    imagedestroy($jpg_image);
    ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM