help array fonts

hello,
i used this code but i failed
$cou = rand(1, 9);
$cou = $cou-1;
$fonts = array(
‘Antykwa’ => array(‘spacing’ => -1, ‘minSize’ => 27, ‘maxSize’ => 30, ‘font’ => ‘AntykwaBold.ttf’),
‘Candice’ => array(‘spacing’ =>-1.5,‘minSize’ => 28, ‘maxSize’ => 31, ‘font’ => ‘Candice.ttf’),
‘DingDong’ => array(‘spacing’ => -2, ‘minSize’ => 24, ‘maxSize’ => 30, ‘font’ => ‘Ding-DongDaddyO.ttf’),
‘Duality’ => array(‘spacing’ => -2, ‘minSize’ => 30, ‘maxSize’ => 38, ‘font’ => ‘Duality.ttf’),
‘Heineken’ => array(‘spacing’ => -2, ‘minSize’ => 24, ‘maxSize’ => 34, ‘font’ => ‘Heineken.ttf’),
‘Jura’ => array(‘spacing’ => -2, ‘minSize’ => 28, ‘maxSize’ => 32, ‘font’ => ‘Jura.ttf’),
‘StayPuft’ => array(‘spacing’ =>-1.5,‘minSize’ => 28, ‘maxSize’ => 32, ‘font’ => ‘StayPuft.ttf’),
‘Times’ => array(‘spacing’ => -2, ‘minSize’ => 28, ‘maxSize’ => 34, ‘font’ => ‘TimesNewRomanBold.ttf’),
‘VeraSans’ => array(‘spacing’ => -1, ‘minSize’ => 20, ‘maxSize’ => 28, ‘font’ => ‘VeraSansBold.ttf’),
);

imagettftext($im, 20, 0, 4, 6, $text_color, $fonts[$cou], $text);

but not work this array

hi,

Try this:
[php]<?php

function imagettftextSp($image, $size, $angle, $x, $y, $color, $font, $text, $spacing = 0)
{
if ($spacing == 0)
{
imagettftext($image, $size, $angle, $x, $y, $color, $font, $text);
}
else
{
$temp_x = $x;
$temp_y = $y;
for ($i = 0; $i < mb_strlen($text); $i++)
{
imagettftext($image, $size, $angle, $temp_x, $temp_y, $color, $font, mb_substr($text, $i, 1));
$bbox = imagettfbbox($size, 0, $font, mb_substr($text, $i, 1));
$temp_x += cos(deg2rad($angle)) * ($spacing + ($bbox[2] - $bbox[0]));
$temp_y -= sin(deg2rad($angle)) * ($spacing + ($bbox[2] - $bbox[0]));
}
}
}

$fonts = array(
‘Antykwa’ => array(‘spacing’ => -1, ‘minSize’ => 27, ‘maxSize’ => 30, ‘font’ => ‘AntykwaBold.ttf’),
‘Candice’ => array(‘spacing’ =>-1.5,‘minSize’ => 28, ‘maxSize’ => 31, ‘font’ => ‘Candice.ttf’),
‘DingDong’ => array(‘spacing’ => -2, ‘minSize’ => 24, ‘maxSize’ => 30, ‘font’ => ‘Ding-DongDaddyO.ttf’),
‘Duality’ => array(‘spacing’ => -2, ‘minSize’ => 30, ‘maxSize’ => 38, ‘font’ => ‘Duality.ttf’),
‘Heineken’ => array(‘spacing’ => -2, ‘minSize’ => 24, ‘maxSize’ => 34, ‘font’ => ‘Heineken.ttf’),
‘Jura’ => array(‘spacing’ => -2, ‘minSize’ => 28, ‘maxSize’ => 32, ‘font’ => ‘Jura.ttf’),
‘StayPuft’ => array(‘spacing’ =>-1.5,‘minSize’ => 28, ‘maxSize’ => 32, ‘font’ => ‘StayPuft.ttf’),
‘Times’ => array(‘spacing’ => -2, ‘minSize’ => 28, ‘maxSize’ => 34, ‘font’ => ‘TimesNewRomanBold.ttf’),
‘VeraSans’ => array(‘spacing’ => -1, ‘minSize’ => 20, ‘maxSize’ => 28, ‘font’ => ‘VeraSansBold.ttf’),
);

$font = $fonts[array_rand($fonts)];

// Create a 300x100 image
$im = imagecreatetruecolor(300, 100);
$red = imagecolorallocate($im, 0xFF, 0x00, 0x00);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);

// Make the background red
imagefilledrectangle($im, 0, 0, 299, 99, $red);

// Path to our ttf font file
$font_file = DIR . ‘/fonts/’ . $font[‘font’];
$font_size = rand($font[‘minSize’], $font[‘maxSize’]);
$spacing = $font[‘spacing’] * 4;

// Draw the text ‘PHP Manual’ using font size 13
imagettftextSp($im, $font_size, 0, 10, 55, $black, $font_file, ‘PHP Manual’, $spacing);

// Output image to the browser
header(‘Content-Type: image/png’);

imagepng($im);
imagedestroy($im);[/php]

not work i try

I placed fonts into “./fonts” folder.

If your fonts are in the same folder where script is, then try to replace this
[php]$font_file = DIR . ‘/fonts/’ . $font[‘font’];[/php]
to [php]$font_file = DIR . ‘/’ . $font[‘font’];[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service