Reputation: 3
Below is the code to generate an image dynamically in php. I want to add some image in this dynamically created image. I've already tried my luck with imagecopy but failed because I think it deals with the already created image to copy one onto another.
<?php
$my_img = imagecreate( 1200, 630 );
$background = imagecolorallocate( $my_img, 2,144,162 );
$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
$text_colour1 = imagecolorallocate( $my_img, 255, 255, 255 );
$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
$font='C:\Windows\Fonts\ARLRDBD.ttf';
imagettftext($my_img, 48, 0, 450, 100, $text_colour, $font,"Hello World");
$font1='C:\Windows\Fonts\Arial.ttf';
imagettftext($my_img, 32, 0, 650, 160, $text_colour1, $font1,Hello World" );
imagettftext($my_img, 32, 0, 500, 300, $text_colour1, $font1,"Hello World" );
imagettftext($my_img, 32, 0, 560, 440, $text_colour1, $font1,"Hello World" );
header( "Content-type: image/png" );
imagepng( $my_img );
imagepng( $my_img,'Ethers.png' );
imagecolordeallocate( $text_colour );
imagecolordeallocate( $text_colour1 );
imagecolordeallocate( $background );
imagedestroy($my_img);
header('Content-Type: image/png');
imagedestroy($my_img);
?>
Upvotes: 0
Views: 137
Reputation: 220
There are readymade code available for playing with image edits.
Find the class from the following link.
http://www.phpclasses.org/package/6323-PHP-Manipulate-GIF-JPEG-and-PNG-images.html
This class can be used to manipulate GIF, JPEG and PNG images.
It can load an image in GIF, JPEG and PNG formats and perform several types of operations.
Currently it can resize the image, render a text on the image, render a watermark image and apply several types of effects like blur, edge detection, sharpen, emboss, etc..
The resulting image can be saved to a file or displayed as the current script output also in GIF, PNG and JPEG formats.
Upvotes: 1