PHP - 将图像放在另一个图像上 [英] PHP - Place an image over another image

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

问题描述

我想使用php将图像放在另一个图像上。我有两张照片。一张是照片。另一个是固定大小,全白的图像。我们可以称之为框架。所以我需要的是将照片放在画面的中间(白色图像),然后保存。任何人都可以帮助我吗?

I want to place an image over another image using php. I have two images. One is a photo. And other one is a image, of fixed size, full white. We can call this as frame. So what i need is place the photo in the middle of the frame (white image) and then save it. Can anyone pls help me?

推荐答案

要做这种工作,你需要使用GD library ImageMagic

to do this kind of work, you need to use GD library or ImageMagic

此代码适用于GD库

       $photo_to_paste="image_to_paste.jpg";  //image 321 x 400
       $white_image="white_image.jpg"; //873 x 622 

        $im = imagecreatefromjpeg($white_image);
        $condicion = GetImageSize($photo_to_paste); // image format?

        if($condicion[2] == 1) //gif
        $im2 = imagecreatefromgif("$photo_to_paste");
        if($condicion[2] == 2) //jpg
        $im2 = imagecreatefromjpeg("$photo_to_paste");
        if($condicion[2] == 3) //png
        $im2 = imagecreatefrompng("$photo_to_paste");

        imagecopy($im, $im2, (imagesx($im)/2)-(imagesx($im2)/2), (imagesy($im)/2)-(imagesy($im2)/2), 0, 0, imagesx($im2), imagesy($im2));

        imagejpeg($im,"test4.jpg",90);
        imagedestroy($im);
        imagedestroy($im2);

该代码将输出:

that code will output:

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

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