Re: alguien ha manejado la imagettfbbox? me da siempre error al cargar el font y os aeguro que el archivo existe y esta donde debe estar en el
directorio /fonts de mi web

From: Date: Mon, 15 Sep 2008 16:51:42 +0000
Subject: Re: alguien ha manejado la imagettfbbox? me da siempre error al cargar el font y os aeguro que el archivo existe y esta donde debe estar en el
directorio /fonts de mi web
References: 1  Groups: php.general.es 
Request: Send a blank email to general-es+get-63144@lists.php.net to get a copy of this message
Esto uso yo para crear claves: function getClauEnImatge($text="",$total_lletres=5) { if(trim($text)==""){$text=getClauEnText($total_lletres);} $host_direccio_real = path_absoluto_del_servidor; //A mi, con la dirección relativa no me funcionaba (esta protegido en el server...) $total_text_width=0; $font_size=14; $font_name=$host_direccio_real."fonts/Comic_Sans_MS.ttf"; $img_width=($font_size+$font_size/4)*($total_lletres+1); $img_height=30; $imatge = @imagecreatetruecolor($img_width, $img_height); //imagealphablending($imatge,true); @imagefilledrectangle($imatge, 0, 0, $img_width, $img_height, imagecolorallocate($imatge,255,244,224)); $color=@imagecolorallocate($imatge,0,0,0); for($i=0;$i<strlen($text);$i++) { $text_angle=11*rand(-1,1); $lletra=substr($text,$i,1); $marc_text = @imagettfbbox($font_size,$text_angle,$font_name,$lletra); $text_width=abs($marc_text[2]-$marc_text[0]); $text_height=abs($marc_text[1]-$marc_text[7]); while($text_width>$img_width*0.90 || $text_height>$img_height*0.90) { $font_size*=0.90; $marc_text = @imagettfbbox($font_size,$text_angle,$font_name,$lletra); $text_width=abs($marc_text[2]-$marc_text[0]); $text_height=abs($marc_text[1]-$marc_text[7]); } if($total_text_width==0){$total_text_width=$text_width/4;} @imagettftext($imatge, $font_size, $text_angle,$total_text_width, $img_height/2+$text_height/2-2, $color, $font_name, $lletra); $total_text_width+=$text_width+$text_width/4; } $nomFich="key_".time().".gif"; @imagegif($imatge,$host_direccio_real."img_temp/".$nomFich); //@imagedestroy($imatge); return array(getConfiguracio("host_direccio_url_relativa")."img_temp/".$nomFich,$host_direccio_real."img_temp/".$nomFich); } josu udaondo escribió:
Ejecuto este código: function calculateTextBox($font_size, $font_angle, $font_file, $text) { // Codigo simple par aver si estoy en desarrollo o en produccion y de donde tengo que coger el archivo. $mivar1 = get_web_tienda($_SESSION['tienda']);
                if (!ModoProduccion())    $mivar2 =
$mivar1[0]['desarrollo'];
                else $mivar2 = $mivar1[0]['produccion'];
                $mifont = $mivar2.ROOT.'/'.URLFonts().'/'.$font_file;
                if (!is_file($mifont)) $mifont =
$mivar2.ROOT.'/'.URLFonts().'/arial.ttf';
                echo $mifont.'<br>'; // esta línea escribe este texto lo
cual indica que el archivo esta bien referenciado: ‘localhost/v1/fonts/arial.ttf’ si lo pongo en el IE me descarga el archivo arial.ttf o sea que esta bien
                $box = imagettfbbox($font_size, $font_angle, $mifont,
$text);
    $min_x = min(array($box[0], $box[2], $box[4], $box[6]));
    $max_x = max(array($box[0], $box[2], $box[4], $box[6]));
    $min_y = min(array($box[1], $box[3], $box[5], $box[7]));
    $max_y = max(array($box[1], $box[3], $box[5], $box[7]));
    return array(
        'left' => ($min_x >= -1) ? -abs($min_x + 1) : abs($min_x + 2),
        'top' => abs($min_y),
        'width' => $max_x - $min_x,
        'height' => $max_y - $min_y,
        'box' => $box
    );
} Function CuentaPixels($texto) { echo REFERENCIA_FONTSIZE .' de tamaño<br>'; // FONT_SIZE es una constante que vale 11 echo REFERENCIA_TIPOLETRA .' de tipo letra<br>'; // REFERENCIA_TIPOLETRA vale ‘arial.ttf’ $retorno = calculateTextBox( REFERENCIA_FONTSIZE ,0 , REFERENCIA_TIPOLETRA , $texto); return $retorno['width']; } function EscribeReferencia($texto) { $limite = REFERENCIA_WIDTH; // vale 128 que son los pixels que me caben en la caja y el $texto es ‘MINITORRE’ $ncontador = 1; echo $limite.' pixels de limite<br>'; echo $texto.'<br>'; echo Cuentapixels($texto).' pixels'; //while (Cuentapixels(substr($texto,1,$ncontador))<=$limite) $ncontador++; una vez que cuentapixels devuelva bien el valor esta línea quitara letras hasta ver lo que cabe en los pixels disponibles.. echo substr($texto,1,$ncontador-1); } Y esto es lo que me devuelve la pantalla: MINITORRE --àesto es $texto
Ref.: 128 pixels de limite                                             ->
esto es $limite 9,20E+16 11 de tamaño arial.ttf de tipo letra localhost/v1/fonts/arial.ttf Warning: imagettfbbox() [function.imagettfbbox <http://localhost/v1/site/function.imagettfbbox> ]: Invalid font filename in D:\xampp\htdocs\v1\include\general.php on line 305 0 pixels o sea cuentapixels me devuelve siempre 0 porque no carga el Font. GDINFO me devuelve esto: array(12) { ["GD Version"]=> string(27) "bundled (2.0.34 compatible)" ["FreeType Support"]=> bool(true) ["FreeType Linkage"]=> string(13) "with freetype" ["T1Lib Support"]=> bool(true) ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(true) ["JPG Support"]=> bool(true) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XPM Support"]=> bool(false) ["XBM Support"]=> bool(true) ["JIS-mapped Japanese Font Support"]=> bool(false) } Que hago mal? Fdo Josu Udaondo Orúe
-- Rolan Benavent Dulasoft, s.l. info@dulasoft.com <mailto:info@dulasoft.com> *PCMark3t.com*, tu tienda de informática en internet <http://www.pcmark3t.com> *Dulasoft.com*: consultoría informática, diseño gráfico, programación de páginas web y aplicaciones de software, montaje de redes, formación a empresas y particulares... <http://www.dulasoft.com>

« previous php.general.es (#63144) next »