I am using SimpleSoftwareIO (https://www.simplesoftware.io/simple-qrcode/) to generate QR Code in Laravel but I need to add text under QR code and when we download, it should download with text.
By using the below code I am able to create QR code:
In controller
$data="Hello";
$path = "logo.png";
$png = QrCode::format('png')->merge($path, .17, true)->size(300)->errorCorrection('H')->generate($data);
$png = base64_encode($png);
In blade file
<img src='data:image/png;base64,{{ $png }}'>
looking for something like this and it should be image
Your text could be another Image. In Intervention Package you can merge two images vertically to achieve this after the QR code generates.
see: http://image.intervention.io/api/insert
or you can use PHP default function imagecopymerge
see: https://www.php.net/manual/en/function.imagecopymerge.php
example:(from official docs)
<?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);
?>
Related
I created an uploader for myself, now what I am trying is adding text on it too. I already created it outside the uploader but I just can't combine them two, already tried multiple sequences but failed :( need help here's the code.!
Here is the upload code.
$file_name = $_FILES[attach][name];
$caption=$_POST["caption"];
$uploaddir = "../photos";
$up_path=$uploaddir."/".$file_name;
move_uploaded_file($_FILES['attach']['tmp_name'], $up_path);
Here's the text on img code:
$get_image = imagecreatefromjpeg('name.jpg');
$white = imagecolorallocate($get_image, 255, 255, 255);
$txt = "Hello World";
$font = "arial.ttf";
imagettftext($get_image, 24, 0, 5, 24, $white, $font, $txt);
header('Content-type: image/jpeg');
imagejpeg($get_image, "name.jpg", 100);
imagedestroy($get_image);
You can achieve watermarking using image libraries.
You can find examples here.
Add 'Watermark' to images with php
An alternative way is to use FFMPEG Library which can be executed through php exec() method. See the link below.
How to add transparent watermark in center of a video with ffmpeg?
is there a function that will convert hex colors to image and save it as png?
example :
$pixelrow1 ["000000","000000","000000"];
$pixelrow2 ["000000","FFFFFF","000000"];
$pixelrow3 ["FF0000","00FF00","0000FF"];
function convert_to_image($row1,$row2,$row3,$path_to_save) {
// Some function
}
convert_to_image($pixelrow1,$pixelrow2,$pixelrow3,"c:/image.png");
I really have no idea if is it possible or not, but i'm pretty sure that its possible because you can make image using php
The output should return like this :
You can do it like this, but hopefully your variables have more sensible names and you can use a loop:
<?php
$im = imagecreate(3,3);
$black = imagecolorallocate($im,0,0,0);
$white = imagecolorallocate($im,0xff,0xff,0xff);
$red = imagecolorallocate($im,0xff,0,0);
$green = imagecolorallocate($im,0,0xff,0);
$blue = imagecolorallocate($im,0,0,0xff);
# First row
imagesetpixel($im,0,0,$black);
imagesetpixel($im,1,0,$black);
imagesetpixel($im,2,0,$black);
# Second row
imagesetpixel($im,0,0,$black);
imagesetpixel($im,1,1,$white);
imagesetpixel($im,2,1,$black);
# Third row
imagesetpixel($im,0,2,$red);
imagesetpixel($im,1,2,$green);
imagesetpixel($im,2,2,$blue);
imagepng($im,"result.png");
?>
The real problem is not saving the data into the file you want.
The real problem is saving the data IN png format.
You should read how png saves the data.
Or you can play a little with PHP image resources.
Maybe this snippet of code can give you some advice:
<?php
header("Content-Type: image/png");
$im = #imagecreate(1, 1);
// Creates a 1x1 image resource
$background_color = imagecolorallocate($im, 0xFF, 0x00, 0x00);
// Adds a red background color to the only pixel in the image.
imagepng($im);
// Sends the image to the browser.
imagedestroy($im);
?>
If you wanna take a look at all the functions for the images:
http://php.net/manual/en/ref.image.php
I want to crop a part of an image of 100x100px for example from the middle to 20px height and 30px width and then save it in another file all with PHP.
I was reading and testing some code but i think im lost.
I want to do this because later i want to use OCR to get the text from the new img cropped.
Any help would be great!
Here is some code that i found in the documentation of php.net
<?php
// Create image instances
$src = imagecreatefrompng('waka.png');
$dest = "Select somehow /images ";
// Copy
imagecopy($dest, $src, 0, 0, 20, 13, 80, 40);
// Output and free from memory
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
?>
Im just getting some error about the img can't show when i run it in my local server.
I'm not really sure what i need to change to get a new png. Actually i have 2 img waka.png and wuku.png for testing.
Starting with your code, this one works for me:
<?php
// load your source image
$src = imagecreatefrompng('1.png');
// create an image resource of your expected size 30x20
$dest = imagecreatetruecolor(30, 20);
// Copy the image
imagecopy(
$dest,
$src,
0, // 0x of your destination
0, // 0y of your destination
50, // middle x of your source
50, // middle y of your source
30, // 30px of width
20 // 20px of height
);
// The second parameter should be the path of your destination
imagepng($dest, '2.png');
imagedestroy($dest);
imagedestroy($src);
You should have 2.png being your cropped image.
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?
Here is an example.
I have 2 images:
https://s-media-cache-ak0.pinimg.com/736x/d1/2e/9e/d12e9ecd9f4c4e45dafa5880c7d99c73.jpg
http://cf.juggle-images.com/matte/white/280x280/php-1-logo-primary.jpg
Steps:
Set the content type header - in this case image/jpg
Create new canvas, width: 720, height: 637
Create two new images from file or URL, $icon1 & $icon2
Copy part of $icon1 to $canvas
Copy and resize part of $icon2 to $can
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);
?>
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
I want to upload an image with some text on it, but when I'm uploading my PHP script it's not working with an image, it shows error every time. And also i want to add some html in the same file I had tried to put that php In html tag and show that image in the center how to do so
My PHP code is:
result.php
<?php
header('Content-type: image/jpeg');
$jpg_image = imagecreatefromjpeg('image.jpg');
$white = imagecolorallocate($jpg_image, 255, 255, 255);
$font_path = 'font.TTF';
$text = $_GET["name"];
imagettftext($jpg_image, 25, 0, 75, 300, $white, $font_path, $text);
imagejpeg($jpg_image);
imagedestroy($jpg_image);
?>
$_GET["name"]; is used for getting text form HTML by input tag, and for your information I have used form method to get the text I want an working example.
The image I want to use is http://images.visitcanberra.com.au/images/canberra_hero_image.jpg
So please use that image only while giving answer
this line will describe the name of image $jpg_image = imagecreatefromjpeg('image.jpg'); and image name is image.jpg
as you mentioned The image I want to use is http://images.visitcanberra.com.au/images/canberra_hero_image.jpg
this is image name canberra_hero_image.jpg right, how come php will work, first rename and use single name
better rename you php
this is the reason you see only text and not image
Change your code from '$jpg_image = imagecreatefromjpeg('image.jpg');' to this code
$image_path = ''http://images.visitcanberra.com.au/images/canberra_hero_image.jpg'';
$jpg_image = imagecreatefromjpeg($image_path);