Imagine I have 2 pictures, imagea.jpg and imageb.jpg
Image A
Image B
I want to combine these both pictures un just 1 and output them to a file imageab.jpg, just like here
I will do this running cron jobs, so I need to do that on PHP, but I'm getting troubles with previous codes. As additional information, I'm getting the ImageA/B URLs from MySQL and all pictures have the same width and height.
Thanks!
You can use imagecopymerge:
Something like this:
$dest = imagecreatefromgjpg('imagea.jpg');
$src = imagecreatefromjpg('imageb.jpg');
// Copy and merge
imagecopymerge($dest, $src, 10, 10, 0, 0, 100, 47, 75);
// Output and free from memory
header('Content-Type: image/jpeg');
imagejpeg($dest);
imagedestroy($dest);
imagedestroy($src);
Imagick is your friend.
For example Imagick::appendImages.
Take a look at GD and imagemagick, they are plenty of functions that can help you:
http://php.net/manual/en/function.imagecopymerge.php
Related
So I'm looking to create an internal tool where our employees can upload a picture of themselves, which automatically merges it with a white border at the bottom (company logo border) and their name on top of it. This way the offices can easily print the pictures for employee boards
So what I need is:
- merge border, picture and text into one image.
- Upload function with crop tool.
What I found is:
- PHP Image Magician (http://phpimagemagician.jarrodoberto.com/)
This basically has all functions I need available so naturally I got excited but I ran across one thing:
In the 14.1_upload.php file it refers to the following:
require_once('image_lib/upload_class.php');
the image_lib/upload_cass.php file doesnt come with the download from the website.
Is there something I'm missing or would you guys recommend not to use PHP Image Magician at all?
I'm looking to make it a very basic and simple tool but functional.
Thanks a bunch in advance
Uploading Image is a very easy process, you can use W3School reference to understand it well http://www.w3schools.com/php/php_file_upload.asp
About Image merge you can use below code:
<?php
$dest = imagecreatefrompng('vinyl.png');
$src = imagecreatefromjpeg('cover2.jpg');
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagecopymerge($dest, $src, 10, 9, 0, 0, 181, 180, 100); //have to play with these numbers for it to work for you, etc.
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
?>
I am creating an application in php in which i upload a image and resize it and place it on a Coffee Mug. Coffee mug is a background image of a div. Now i want to save both images as a single image it would look like a screenshot of a coffee mug with the image printed on it. How to take screenshot of only mug and image on it or if there is an another way to doing it in php.
You need an image library for that. Most PHP versions on many servers are precompiled with GD. This is a limited and not so well performing library, so most people will use Imagemagick.
In GD:
$mug = imagecreatefrompng('mug.jpg');
$overlay = imagecreatefromjpeg('photo.png');
imagecopy($mug, $overlay);
In Imagemagick:
$mug = new Imagick("mug.jpg");
$overlay = new Imagick("logo.png");
$composition = new Imagick();
$composition->compositeImage($mug);
$composition->compositeImage($overlay);
You can do this by using the GD2 library:
<?php
$image = imagecreatefromstring(file_get_contents($image_path);
$coffe_mug= imagecreatefromstring(file_get_contents($coffe_mug_path));
// merge the two
imagecopymerge($image, $coffe_mug, 10, 10, 0, 0, 100, 47, 75);
// save, can also be imagepng, imagegif, etc, etc
imagejpeg($image, '/path/to/save/image.png');
?>
You can also output the image to the browser, for more info check: http://php.net/manual/es/function.imagecopymerge.php.
I use this code to merge two images. Can someone please help me to merge 2 source images with 1 base image. For eg. I have these images base.jpg, image1.jpg, image2.jpg. I want to merge image1.jpg and image2.jpg on base.jpg. I'm using this code to merge two images.
$dest = imagecreatefromjpeg('base.jpg');
$src = imagecreatefromjpeg('$image1.jpg');
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagecopymerge($dest, $src, 229, 285, 0, 0, 70, 70, 100);
Imagejpeg($dest, '$new.jpg', 100);
imagedestroy($dest);
imagedestroy($src);
Basically we will be putting many different images all together on one big ‘canvas’ image. If you need to do that for some reason, read on to find out how.
Combining multiple images using PHP
I'm trying to create a produkt configurator similar to: http://winmap.active-online.de/kler/pol/index.php3?room_name=200D
I'd like to put texture or color on diffrent image elements and put it together into one result image.
I'm trying to usa like this:
header('Content-Type: image/jpeg');
$poszycie = imagecreatefrompng('poszycie.png');
$tekstura = imagecreatefrompng('tekstura.png');
//imagefilter($poszycie,IMG_FILTER_EMBOSS);
//imagepng($tekstura);
//$bcg = imagecreatefromjpeg('las.jpg');
//$img = imagecreatefromjpeg('zdjecie.jpg');
//imagecopymerge($poszycie, $tekstura, 0, 0, 0, 0, imagesx($poszycie), imagesy($poszycie), 75);
//imagepng($poszycie, null, 100);
imagecopymerge($poszycie, $tekstura, 0, 0, 0, 0, imagesx($poszycie), imagesy($poszycie), 50);
imagepng($poszycie);
but result is :http://saveur.pl/testgd/configurator.png
Thanks for any help.
I think you'll be better off with ImageMagick. For example you could use these tricks http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=14513&start=15 and I'm sure a web search for imagemagick texture image area would reveal more ideas.
Anyway you'll have to take apart the image and use the alpha channel.
I think my answer to this question can help. The problem deals with alpha channel. Besides, you should send this header (png instead of jpeg):
header('Content-Type: image/png');
since you are calling
imagepng($poszycie);
which may be another cause of trouble.
Is there a PHP function that would allow me to superimpose an image over another one? If not, how can I accomplish this (not asking for code, just a list of steps)?
I suppose there are functions provided by GD (generally enabled on PHP installations) that might do just that.
For instance, maybe one of imagecopy or imagecopymerge functions, I'd say.
See Example #1 Merging two copies of the PHP.net logo with 75% transparency on the manual page of the second one (quoting) :
<?php
// Create image instances
$dest = imagecreatefromgif('php.gif');
$src = imagecreatefromgif('php.gif');
// Copy and merge
imagecopymerge($dest, $src, 10, 10, 0, 0, 100, 47, 75);
// Output and free from memory
header('Content-Type: image/gif');
imagegif($dest);
imagedestroy($dest);
imagedestroy($src);
?>
There are also these two examples that might prove useful :
Adding watermarks to images using alpha channels
and Using imagecopymerge() to create a translucent watermark
Use the GD graphics library. There is an example of creating a watermark, which is basically the same thing using the imagecopymerge() function.