简体   繁体   中英

Trying to render avatar image over a signature image with PHP

I am making a dynamic signature generator and I would like to add a avatar image in part of the signature. How would I do this as well as sizing down the image?

You can do that by copying one image on the other, with some resampling (to make the avatar smaller, if desired.).

PHP must have GD libs included, if not, make sure you have support for GD, otherwise you cannot use the functions.

Check your GD support: function.gd-info.php

Then start reading here:

function.imagecopy.php

or here: function.imagecopyresampled.php

Here is an example.

I have 2 images:

  1. https://s-media-cache-ak0.pinimg.com/736x/d1/2e/9e/d12e9ecd9f4c4e45dafa5880c7d99c73.jpg
  2. http://cf.juggle-images.com/matte/white/280x280/php-1-logo-primary.jpg

Steps:

  1. Set the content type header - in this case image/jpg
  2. Create new canvas, width: 720, height: 637
  3. Create two new images from file or URL, $icon1 & $icon2
  4. Copy part of $icon1 to $canvas
  5. Copy and resize part of $icon2 to $can
  6. Output image to browser

<?php
header('Content-Type: image/jpg');
$canvas = imagecreatetruecolor(720,  637);
$icon1 = imagecreatefromjpeg('https://s-media-cache-ak0.pinimg.com/736x/d1/2e/9e/d12e9ecd9f4c4e45dafa5880c7d99c73.jpg');
$icon2 = imagecreatefromjpeg('http://cf.juggle-images.com/matte/white/280x280/php-1-logo-primary.jpg');

//add 2 source images
imagecopy($canvas, $icon1, 0, 0, 0, 0, 720,  637);
imagecopyresized($canvas, $icon2, 0, 0, 0, 0, 100, 100, 280, 280);

//Output image to browser
imagejpeg($canvas);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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