I'm trying generate a certificate to print, but the only thing that happens is show a empty square in screen:
I'm trying show the image on the screen before i try to write on it.
header("Content-type: image/jpeg");
$imagem = imagecreatefromjpeg("assets/img/certificado.jpg");
imagejpeg($imagem);
I already check the gd2 extension and it's enable:
And I check the php error log and the page who run this code dont return any error.
When I remove the header("Content-type:image/jpeg"); and put a var_dump($i) it shows me this: resource(12,gd)
Sorry for my english and thanks!
$our_image = imagecreatefromjpeg('upload/promo/flyer_hindi.jpg');
$white_color = imagecolorallocate($our_image, 0, 0, 0);
$font_path = 'upload/promo/CALIBRIB.TTF';
$text = 'some text';
$size = 70;
$angle = 0;
$left = 420;
enter code here
imagettftext($our_image, $size, $angle, $left, $top, $white_color, $font_path, $text);
imagejpeg($our_image, 'upload/promo/' . $id . '.jpg', 80);
i tried this code a last year, i upload a flyer and add some text on fix location and save. i think you need the same.
Related
Want to display the half letters like "અર્થ" and "અસત્ય" in imagefttext function PHP but the result something different. Like this.
Or anyone can help me the alternate way?
<?php
header('Content-type: text/html; charset=utf-8');
#Declare fixed values
$textY = 190;
$textX = 130;
$textY2 = 280;
$textX2 = 130;
$textFont = './fonts/notoSans/NotoSansGujarati-Bold.ttf';
// $textFont = './fonts/Shrikhand-Regular.ttf';
$textSize = 54;
$imagesFolder = './images';
$text = "અર્થ";
$text2 = "અસત્ય";
//header("Content-Type: image/png");
header("Content-Type: image/png");
//Creating background image
$im = imagecreatefrompng('https://i.stack.imgur.com/A9Oll.png');
//$im = imagecreatetruecolor(512,512);
// Create the clours to be used.
$yellow = imagecolorallocate( $im, 255, 255, 0 );
imagefttext( $im, $textSize, 0, $textX, $textY, $yellow, $textFont, $text );
imagefttext( $im, $textSize, 0, $textX2, $textY2, $yellow, $textFont, $text2 );
$imageFile = $imagesFolder.'/'.rand(0,500).'.png';
imagepng( $im, $imageFile );
// Unload resources.
imagedestroy( $im );
?>
=> Edits 0.1:
Issue is getting displaying the half letters in the image.
- Output I needed (I did that in photoshop) : desired Output image
- But I'm getting through this code : image getting from code
Looks like this is not possible with Unicode, and has been a problem for a long time. From a PHP developer on a 10 year old bug:
Thanks, now I got it. The problem isn't particularly related to
Bengali, but rather to combining characters in general, which are
not supported by imagettftext().
I attempted this with the Imagick extension, but had the same output.
A possible workaround is to find a font that uses another encoding such as ISCII, and then convert the text to that encoding using mb_convert_encoding() or similar function.
Or perhaps have the image generated by a command-line tool run with exec().
I have a function set up to create multiple images with unique serial numbers on each of them. The problem is that its creating a small square on the browser and not redirecting the browser after saving back to the dashboard
header("Content-type: image/png");
$imgPath = 'background1.png';
$string = $serialNumber;
$directory = "serial_image/".$string.".png";
$image = imagecreatefrompng($imgPath);
$color = imagecolorallocate($image, 0, 0, 0);
$font = 'arial.ttf';
$fontSize = 13;
$x = 20;
$y = 212;
imagettftext($image, $fontSize, 0, $x, $y, $color, $font, $string);
imagepng($image, $directory);
I call the function to create 10 images each with the unique serial number. They are created but then the browser stops and just shows this square.
I have tried ob_start() and ob_flush() with no luck
I think its a header issue.
Can someone please help with this one.
I have been working on a dynamic image script.The main reason I was searching for it is I want to show user info from a database.Here's my problem:
<?php
header("Content-type:image/png");
$array=array("I am a monument to all your sins", "Currently making pizza","Best before 12/7/09", "Farming Onions");
function imagettftext_cr(&$im, $size, $angle, $x, $y, $color, $fontfile, $text)
{
// retrieve boundingbox
$bbox = imagettfbbox($size, $angle, $fontfile, $text);
// calculate deviation
$dx = ($bbox[2]-$bbox[0])/2.0 - ($bbox[2]-$bbox[4])/2.0; // deviation left-right
$dy = ($bbox[3]-$bbox[1])/2.0 + ($bbox[7]-$bbox[1])/2.0; // deviation top-bottom
// new pivotpoint
$px = $x-$dx;
$py = $y-$dy;
return imagettftext($im, $size, $angle, $px, $y, $color, $fontfile, $text);
}
$image = imagecreate(500,90);
$black = imagecolorallocate($image,0,0,0);
$grey_shade = imagecolorallocate($image,40,40,40);
$white = imagecolorallocate($image,255,255,255);
$text = $array[rand(0,sizeof($array)-1)];
$otherFont = 'open.ttf';
$font = 'open.ttf';
$name = "erlis";
$name = substr($name, 0, 25);
//BG text for Name
while($i<10){
imagettftext_cr($image,rand(2,40),rand(0,50),rand(10,500),rand(0,200),$grey_shade,$font,$name);
$i++;
}
//BG text for saying
while($i<10){
imagettftext_cr($image,rand(0,40),rand(90,180),rand(100,500),rand(200,500),$grey_shade,$otherFont,$text);
$i++;
}
// Main Text
imagettftext_cr($image,35,0,250,46,$white,$font,$name);
imagettftext_cr($image,10,0,250,76,$white,$otherFont,$text);
imagepng($image);
?>
This part works perfectly with simple text and no mysql queryes. But when I try to initiate a mysql query..let's say $query = mysql_query("SELECT * FROM serverplayers WHERE id=1"); it just breaks the image.It doesn't matter what kind of form I use but it just brakes my image.How can I implement some "fetch from the database" code? Maybe $_GET[''] or something like that.
I need the $name="erlis"; to be changed to a users info.
This seems to be a matter of how to debug that beast.
Build yourself a URL that opens the image AND test it in any browser. Something like
http :// yourserver / images?id=1 (adapt this to your needs please - was just an example)
Add your mysql sequence to the code
Uncomment your mimetype header modification like this:
// header("Content-type:image/png");
run the link from step 1 in the browser -> the php/mysql debugging potentially hints you on the error
if you cannot see anything on the browser try 'view source code' from the browser's menu
I have a php file for captcha. But image is not there in web page. I cant find out what is the prob. Please help me. Here is my code.
<?php
ob_start();
session_start();
// Set the content-type
header('Content-Type: image/jpeg');
mimetypes.add_type('application/font-ttf', '.ttf', True)
// Create the image
$im = imagecreatefromjpeg('bg.jpg');
// Create some colors
$R = rand(0,100);
$G = rand(0,100);
$B = rand(0,100);
$cc = imagecolorallocate($im, $R, $G, $B);
// The text to draw
$text = rand(100,10000);
$_SESSION['text'] = $text;
// Replace path by your own font path
$font = 'arial.ttf';
// Add the text
imagettftext($im, rand(40,45), rand(0,1), rand(10,70), rand(38,50), $cc, $font, $text);
$NumberOfLines=15;
imagecolorallocate($im, 15, 142, 210);
$cc=0;
while($cc < $NumberOfLines){
// set random color:::
//assign random rgb values
$c1 = mt_rand(50,200); //r(ed)
$c2 = mt_rand(50,200); //g(reen)
$c3 = mt_rand(50,200); //b(lue)
//test if we have used up palette
if(imagecolorstotal($im)>=255) {
//palette used up; pick closest assigned color
$color = imagecolorclosest($im, $c1, $c2, $c3);
} else {
//palette NOT used up; assign new color
$color = imagecolorallocate($im, $c1, $c2, $c3);
}
// done...
$startH =rand(3,200);
$startTOP = rand(0,8);
$stopH=rand(3,200);
$stopTOP =50;
imageline($im, $startH, $startTOP, $stopH, $stopTOP, $color);
$cc++;
}
// Using imagepng() results in clearer text compared with imagejpeg()
imagejpeg($im);
imagedestroy($im);
?>
Name of this script file is img.php And it is set as src of img
tag like
img src='img.php'
Here arial.ttf file is in the same folder where this php file resides. Please help me for this. This captcha image is not being loaded.
First remove the ob_start() command. It does not make much sense (at least to me).
Then uncomment the header(..) line so that you see error messages in the browser.
I had to do the following things to get the code up and running:
I removed the mimetypes line (is this PHP at all? If yes, a semicolon is missing)
the script did not find the font - I had to use absolute path and set the permissions right
When you are done with debugging and see fancy chars in your browser window, add the header(..) line again.
I've been trying to find a method of achieving this for awhile now with no luck.
Unfortunately none of these formats are supported by ImageMagicK
Thanks
Customize the code to fit into your requirements.
I've attached a sample image generated from a text file that contains "Generating preview images for TXT files" sentence by the following code:
<?php
Header ("Content-type: image/gif");
$txtfile = "test.txt";
$testarr = array();
if(!file_exists($txtfile)){
$string = "File not found.";
}
else{
$testarr = file($txtfile);
srand ((float) microtime() * 10000000);
$string = '-'.$testarr[array_rand($testarr)];
$string = substr($string,0,strlen($string)-2);
}
$font = 4;
$width = ImageFontWidth($font)* strlen($string);
$height = ImageFontHeight($font);
$im = ImageCreate($width,$height);
$x=imagesx($im)-$width ;
$y=imagesy($im)-$height;
$background_color = imagecolorallocate ($im, 242, 242, 242); // white colored background
$text_color = imagecolorallocate ($im, 0, 0,0); // black colored text
$trans_color = $background_color; // transparent
imagecolortransparent($im, $trans_color);
imagestring ($im, $font, $x, $y, $string, $text_color);
imagegif($im);
ImageDestroy($im);
?>
Links would be useful :
http://visionmasterdesigns.com/tutorial-convert-text-into-transparent-png-image-using-php/
http://www.phpro.org/examples/Text-to-Image-with-GD.html
I think you are going to need to do this on a machine with a GUI/Window environment by opening the files and then taking screenshots of them like http://litmus.com/ or https://browserlab.adobe.com/en-us/index.html
There is a program written do this for PDFs from HTML using WebKits rendering engine: http://code.google.com/p/wkhtmltopdf/
My suggestion is to convert all those documents to pdf and then print that pdf to image.
For Doc to PDF, you could try LiveDocx.