gpt4 book ai didi

php - 使用 PHP 将图像放在另一个图像中

转载 作者:可可西里 更新时间:2023-11-01 00:51:31 26 4
gpt4 key购买 nike

我有一张图片,上面的文字是通过 php 表单动态生成的。我将 Logo 图像的位置保存到 mysql 数据库的变量中。有没有办法拍摄这张图片并将其应用到图片中的固定位置?如果需要,必须将其调整得更小以适合该图像区域。

我已经有一个看起来像这样的脚本:

        $img = imagecreatefromjpeg('coupon/coupontemplate.jpg');
$textColor = imagecolorallocate($img, 0, 0, 0); // black text

//Write first the coupon title
imagefttext($img, 16, 0, 20, 34, $textColor, 'coupon/arialbd.ttf', $title);

//Then write the coupon description
imagettftextbox($img, 13, 0, 20, 45, $textColor, 'coupon/arial.ttf', $description, 440);
//If the checkbox to include logo is checked...
if ($_POST['clogo'] == 'y') {

$logo = $row['imagecompany'];
$logo_file = "../directory/memberimages/$logo";
$logo_file_type = getimagesize($logo_file);

if ($logo_file_type['mime'] == 'image/jpg') {
$logoImage = imagecreatefromjpeg($logo_file);
} else if ($logo_file_type['mime'] == 'image/gif') {
$logoImage = imagecreatefromgif($logo_file);
} else if ($logo_file_type['mime'] == 'image/png') {
$logoImage = imagecreatefrompng($logo_file);
}

}

// Output image to the browser
//header('Content-Type: image/jpeg');
//imagejpeg($img);

// Or save to file
imagejpeg($img, 'my-text.jpg');
imagedestroy($img);

}
//}

任何人都知道如何做到这一点——从指定位置获取图像并将其放在另一幅图像上?谢谢!

最佳答案

可以像这样合并图像:reference

<?php
# If you don't know the type of image you are using as your originals.
$image = imagecreatefromstring(file_get_contents($your_original_image);
$frame = imagecreatefromstring(file_get_contents($your_frame_image));

# If you know your originals are of type PNG.
$image = imagecreatefrompng($your_original_image);
$frame = imagecreatefrompng($your_frame_image);

imagecopymerge($image, $frame, 0, 0, 0, 0, 50, 50, 100);

# Save the image to a file
imagepng($image, '/path/to/save/image.png');

# Output straight to the browser.
imagepng($image);

关于php - 使用 PHP 将图像放在另一个图像中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6135653/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com