使用PHP将图像放在另一个图像中 [英] Place image in another image with PHP

查看:163
本文介绍了使用PHP将图像放在另一个图像中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an image on which the text is being dynamically generated via a php form. I have the location of a logo image saved to a variable from a mysql database. Is there a way to take this image and apply it to a fixed position in the image? If need be, it will have to be resized smaller to fit in this image area.

我已经有一个如下所示的脚本:

I already have a script that looks like this:

        $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);

    }
//}

任何人都有想法如何这样做 - 从指定位置获取图像并将其放在另一个图像上?谢谢!

Anyone have ideas how to do this -- get the image from the specified location and put it on the other image? Thanks!

推荐答案

我想你正在寻找 imagecopyresampled() imagecopyresized()

这篇关于使用PHP将图像放在另一个图像中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆