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);
?>
Related
I am coding a Laravel project where I let users add their own small image to a bigger image (something like milliondollarhomepage.com).
I use the PHP imagecopy(); to add the small image to the bigger image. The problem is: the colors get really poor after merging the two images together. I think the new image only has the colors of the previous image, so no new colors can be added to the image.
My code:
$pixel = GET_INFO_HERE;
$dest = imagecreatefrompng(public_path('storage/pixels.png'));//get big image
$src = imagecreatefrompng(public_path('storage/uploads/' . $pixel->imagename));//get small image to add
imagecopy($dest, $src, $pixel->x_position, $pixel->y_position, 0, 0, $pixel->width, $pixel->height);
ob_start();
imagepng($dest);
$newpixelsimg = ob_get_clean();
Storage::put('public/pixels.png', $newpixelsimg);//save new image
imagedestroy($dest);
imagedestroy($src);
I tried to use imagetruecolortopalette($dest, false, 255); before the imagecopy(); method, but it didn't change anything.
I have been searching for solutions for a long time now, but I couldn't get it to work yet.
Is there anyone who has a solution for this?
this is my first question and I'm planning to hang around in this forum. I'm very new to programming since I'm studying but I'm making great progress. So, with this in mind I'll try to be as detailed as possible.
The project I am working with is about creating a png-image using GD PHP. The script recieves data, calculates image WIDTH/HEIGHT according to these. From this data I then print out pixels on the image in different spots. Everything works great, it displays the image and saves it on the server, there's nothing wrong with that. But when I run the script, it outputs the image to the browser. I don't want that. I just want the script to process the image and save it to the server. I have searched plenty but haven't found anything about it.
Code for creating the image: I have to remove some code though, but it's not needed to answer my question. I suspect it's something with the header and imagecreatetruecolor. This is all the data I can give.
<?php
//Some calculations before
// --- START: CREATE IMAGE ---
$png = imagecreatetruecolor($WIDTH, $HEIGHT);
imagesavealpha($png, true);
$trans_colour = imagecolorallocatealpha($png, 0, 0, 0, 127);
imagefill($png, 0, 0, $trans_colour);
//Here's just a loop to print pixels
header("Content-type: image/png");
imagepng($png);
save($png); //Function used for saving
//Erase from memory
imagedestroy($png);
?>
I am searching for a way to overlay an image on an existing image.
e.g:
+
I have found a great example over here: PNG overlay using one single Image element.
but I have two problems with these.
First of all, I don't want the dimensions to be equal to each other. e.g (215*215 on 215*215). This is because my users would have the ability to choose where they want to put their image. (Top, left, bottom, top-right) so 8 directions.
The second problem is that in that example, only 2 images are allowed to overlay. My users (again) will have the ability to put multiple images on top of it.
I have a little knowledge of Javascript and PHP, so it would be great if you guys (and girls) could help me out.
Sincerely,
You can do this using GD library. There is function to "merge" images called imagecopymerge.
Here is a very simple example how to merge images:
<?php
header('Content-Type: image/jpeg');
$bg = imagecreatefromjpeg('background.jpg');
$img = imagecreatefromjpeg('image.jpg');
imagecopymerge($bg, $img, 0, 0, 0, 0, imagesx($bg), imagesy($bg), 75);
imagejpeg($bg, null, 100);
?>
I have used the following code to create jpeg image using existing images. These images have used embedded color profile, Adobe1998 color profile.
header("Content-type: image/jpeg");
$src = imagecreatefromjpeg($upfile);
$dst = imagecreatetruecolor($tn_width, $tn_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
imagejpeg($dst,NULL,100);
imagedestroy($src);
imagedestroy($dst);
The problem here is that when the image is displayed embedded color profile is not seen.
Can anyone help me? What may be the problem ?
Thanks in advance
imagecratefromjpeg() makes use us the GD2-Lib, which seems not to support color profiles. You should consider using imagemagick to resize your image like this:
convert mypicture.jpg -resize 50% resized.jpg
The color profile should be still in the image.
Color profiles are pieces of information embeded in the image specific to the display media that was used originally (basically matches the color-profile for you monitor), so when opening the same image on another media, the colors will be adjusted after opening it to match more closely what you saw initially on your monitor.
Try using convert as schneck sugested, and if that dosen't work, you may also try GIMP from the command line. I've never personally used it from the cmd line, but it does support color profiles, and i know it has some options for batch transformations.
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.