PHP - 将一个图像放在另一个图像上

标签 php image gd image-resizing

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

最佳答案

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

此代码适用于 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);

该代码将输出: imagr

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

相关文章:

javascript - 更好地理解 AJAX

php - 如何在 PHP 中回显 GROUP BY 的第一个值

php - 如何清理 PHP 中的搜索栏字符串

java - 将图像解析为多个图像

image - 将一个Word文档插入另一个中时丢失的VBA图像

php - 拉维尔 5.6 : Create image thumbnails

Ubuntu "GD Library extension not available with this PHP installation.' 上的 Laravel 5.7 '

php - 如何用jquery删除mysql记录

python - Django 通过 iOS 上传图片时图像旋转不正确(EXIF 问题)

PHP getimagesize - 无法打开流。错误的请求