I want to put text over an image using GD.
When I use
ImageTTFText($image, $fontSize, $fontRotation, 7, 22, $colorShadow, 'arial.ttf', $str);
I get
Warning: imagettftext()
[function.imagettftext]: Could not
find/open font in
/home/index.php
on line 17
Can I get PHP or GD to return a list of all available fonts per my system?
Thanks
Update
... or do I need to upload myself all the fonts myself that I wish GD to have access to?
Replace "arial.ttf" with "./arial.ttf", because "arial.ttf" is an absolute path and you need a relative path. Read more on imagettftext here.
To answer your update, yes, you do need the font files in that directory. Here is a really cool site for finding fonts (like arial.ttf): http://www.1001freefonts.com/
Download a font file from there, put it in the folder of your script, and then replace "arial.ttf" with "./filename.ttf".
If you can use Imagemagick there is always that
The fonts can be anywhere,but you must specify the full path to arial.ttf.
Related
I am using TCPDF library with CodeIgniter. How can I add Jameel Noori Nastaleeq fonts?
I have added Jameel_Noori_Nastaleeq.ttf font file under tcpdf\fonts folder, and included it like:
$fontname = $pdf->addTTFfont('/fonts/Jameel_Noori_Nastaleeq.ttf', 'TrueTypeUnicode', '', 32);
$pdf->SetFont('Jameel Noori Nastaleeq', 'BI', 20, '', 'false');
But it is not working. Anyone have an idea, how to include it?
I have applied jameel noori nastaleq font in my android studio app, it's working fine. I tried in this way:
set the name of the file without underscore(_) or dashes (-) with all small letters
don't use .ttf while giving a path of the font.
use this directory drawable/font
Hope this will help you.
I think problem is in path of your font. You must add font with full path. like
/home/username/public_html/...
try to upload your font in root path and locate it with this format.
/home/username/public_html/Jameel_Noori_Nastaleeq.ttf
Is better if you convert the font to ctg.z/z/php files. You can convert ttf fonts with http://fonts.palettize.me and then put uncompressed result in fonts folder into tcpdf class.
Then you can add it with $pdf->SetFont('jameelnoorinastaleeq', 'BI', 20);
I'm creating magento extension for pdf generating. I need to use Verdana Bold,Verdana Reg... fonts to my pdf file which generated using Zend_Pdf. Anyone can explain how to use the proper path for accessing TTF type fonts.
for this first you should upload desired font files into a directory best place to upload a font is inside lib folder so in this demonstration I will use create directory inside lib folder called customfonts and upload my font file there
Now call it on desired php file (ex: inside Shipment.php) and use it like below
$chevinFontBold = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/customfonts/chevin-bold.ttf');
$page->setFont($chevinFontBold, 8);
here 8 is the font size
//load font from file system
$font = Zend_Pdf_Font::fontWithPath("/path/to/myfont.ttf");
//add $font to page
$page->setFont($font, $fontSize);
Hope this helps
I am generating the PDF using TCPDF. The output I get is in Helvetica font but I want it in Frutiger. I have a frutiger.otf file.
I tried the following code
$fontname = $pdf->addTTFfont('Frutiger-45Light.otf', 'TrueTypeUnicode', '', 32);
$pdf->SetFont($fontname);
I am getting an error: could not include font definition file. And I have googled many websites which didn't help.
You cannot use a URL as fontfile. It must be a path in the local filesystem.
If you need a font on a different server you first must download it yourself. Since fonts are static you should do this manually.
I'm using the TCPDF library to generate a PDF file with PHP. I want to use a custom font so I used the addTTFfont method to add my custom TrueType font files. The font I am trying to add is "Aller" from fontsquirrel.com
$aller = $pdf->addTTFfont($_SERVER['DOCUMENT_ROOT'].'/includes/fonts/Aller/Aller_Rg.ttf', 'TrueTypeUnicode', '', 32);
This created the files aller_rg.php, aller_rg.ctg.z, and aller_rg.z in my TCPDF fonts folder. The K_PATH_FONTS constant points to this directory. The addTTFfont method returns the string name of the font. It would return false if there was an error so the problem is probably not here..
I then tried to use the font
$pdf->SetFont($aller, '', 16); // or $pdf->SetFont('aller_rg', '', 16);
$pdf->Write(0,"abcdefg",'',0,'L',true,0,false,true,0);
The pdf is generated without any errors. When viewsed in the browser preview the font is clearly not aller but just a generic sans-serif.. When I open the pdf in Mac's Preview application the sections that are using the aller font are blank (no text displays).
Anyone know what I'm doing wrong?
Got it to work by using this tool
http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf
it generates a .php, .z, and .afm file that you put in the TCPDF fonts directory. I'm still not sure what the problem was. the addTTFfont() method doesn't create the .afm file so maybe that's it?
I had the same problem:
The TCPDF converted font did not display, but the one converted with the following link did:
http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf
So I compared the two and found out that xml-convert.com was using "TrueType" instead of "TrueTypeUnicode" as font type. For me it worked to change the argument to "TrueTypeUnicode". Try:
$aller = $pdf->addTTFfont($_SERVER['DOCUMENT_ROOT'].'/includes/fonts/Aller/Aller_Rg.ttf', 'TrueType', '', 32);
I need a PHP script to convert favicons to PNGs while keeping their original dimensions.
I know Google has it's secret icon converter - http://www.google.com/s2/favicons?domain=http://facebook.com/ but this converts favicons to 16x16 even if they they were originally larger. So basically I need this, minus the shrinking effect.
I've also seen this - http://www.controlstyle.com/articles/programming/text/php-favicon/ but I couldn't get it to work after hours of messing around with it.
Basically I am trying to automatically grab the icon for a link that will be as large as possible - automatically 48x48 png based on a URL would be the perfect scenario, but I don't know of any humanly possible way to do this given that no websites happen to keep a 48x48 icon in a publicly accessible spot.
Does anybody know of a script/service or have a suggestion? Thanks!
So I ended up using a class called FloIcon that could convert BMPs to ICO. I should note that it's always important to check the file type of an icon and not assume that .ico means bmp because some sites (like Facebook) were actually PNG).
#goker.cebeci Your service looks awesome! The main thing is that I needed my icons to be the maximum size when possible, so I just wrote my own script.
Here is a function to convert from bmp(ico) to png
http://us3.php.net/manual/en/function.imagecreate.php#53879
Download the ico to your server (file_get_contents or other methods) usually is favicon.ico at the base url, or scrape the html code for the <link rel="shortcut icon" href="ico_url_here" type="image/x-icon" /> element and extract the href
use the function from the link above to convert to the png
use the GD functions to open and resize
$image = imagecreatefrompng($filename);
$resized_image = imagecreatetruecolor($NewWidth, $NewHeight);
imagecopyresampled($resized_image, $image, 0, 0, 0, 0, $NewWidth, $NewHeight, $OriginalWidth, $OriginalHeight);
4 Save the file (imagepng or similar)
I used Imagemagick on my favicon to PNG convertor web service project.
convert "favicon.ico" -thumbnail 16x16 -alpha on -background none -flatten "favicon.png"
Some websites' favicons have scene and their sizes are bigger than 16x16 pixels
eg: http://blogger.com/favicon.ico
http://www.google.com/s2/favicons?domain=http://facebook.com/ does not work properly. So, I developed a web service for this.
If you want to try my web service you can go this way
http://geticon.org/of/http://facebook.com/ or this way
http://geticon.org/of/facebook.com
Code at http://www.controlstyle.com/articles/programming/text/php-favicon/ has small error:
You need to change $entry['swBitCount'] to $entry['wBitCount']. When I have made that changing all work right
imagecopyresized - the docs contains the example as well
The above require compiled with option --with-gd
I assume you did not aware of imagick extension as well
etc:
all possible image processing extensions/functions
Im using here: http://plugins.trac.wordpress.org/browser/wp-favicons/trunk/plugins/filters/convert_to_png.php a lib from here: http://www.tom-reitz.com/2009/02/09/ico-images-in-facebook-profile-boxes/
(I did not want to save the ico's to disk first)
The only problem with the lib is that it sometimes fails on the XOR e.g. on this favicon: http://www.slatch.com/
So that is something I need to fix in it but furthermore it worked great for thousands of icons.