Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

PHP GD problem sa našim slovima

[es] :: PHP :: PHP GD problem sa našim slovima

[ Pregleda: 3187 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

semsudin
BIH

Član broj: 13751
Poruke: 58
*.asa-sped.ba.

Sajt: www.hostbih.com


Profil

icon PHP GD problem sa našim slovima12.09.2007. u 10:37 - pre 202 meseci
Zdravo


Koristim PHP GD za automatsko kreiranje slicica, koje u sebi sadrže podlogu i tekst.
Tekst se prosljeđuje preko $_GET-a, sve radi ok, generiše se sličica, ali problem je sa našim slovima čćžšđ.

Problem mi je što mi tekst koje se generiše unutar sličice umjesto naših slova čćžšđ sadrži neke hiroglife.

Zna li ko kako riješiti ovaj problem, inače koristim UTF-8 encoding.



Zdravo
 
Odgovor na temu

bzero
dev null
europe

Član broj: 5907
Poruke: 371
*.dynamic.sbb.co.yu.

Jabber: bzero@elitesecurity.org
Sajt: www.google.com/search?q=b..


Profil

icon Re: PHP GD problem sa našim slovima12.09.2007. u 12:09 - pre 202 meseci
Koju GD funkciju koristis za ispisivanje teksta? Ako koristis imagestring() nece raditi nasa slova.
Za UTF-8 koristi ImageTTFText() + stavi neki .ttf koji podrzava nasa slova (npr arial).

http://www.php.net/imagettftext
Never trust an operating system you don't have sources for.
 
Odgovor na temu

semsudin
BIH

Član broj: 13751
Poruke: 58
*.asa.ba.

Sajt: www.hostbih.com


Profil

icon Re: PHP GD problem sa našim slovima12.09.2007. u 12:18 - pre 202 meseci
Probao sam obicni font npr. arial ali ne ide:

Inece koristim dynamic text replacment skriptu:



Code:

<?php
/*
    Dynamic Heading Generator
    By Stewart Rosenberger
    http://www.stewartspeak.com/headings/    

    This script generates PNG images of text, written in
    the font/size that you specify. These PNG images are passed
    back to the browser. Optionally, they can be cached for later use. 
    If a cached image is found, a new image will not be generated,
    and the existing copy will be sent to the browser.

    Additional documentation on PHP's image handling capabilities can
    be found at http://www.php.net/image/    
*/


$font_file  = 'arial.ttf' ;
$font_size  = 50 ;
$font_color = '#000000' ;
$background_color = '#ffffff' ;
$transparent_background  = true ;
$cache_images = true ;
$cache_folder = 'cache' ;







/*
  ---------------------------------------------------------------------------
   For basic usage, you should not need to edit anything below this comment.
   If you need to further customize this script's abilities, make sure you
   are familiar with PHP and its image handling capabilities.
  ---------------------------------------------------------------------------
*/

$mime_type = 'image/png' ;
$extension = '.png' ;
$send_buffer_size = 4096 ;

// check for GD support
if(!function_exists('ImageCreate'))
    fatal_error('Error: Server does not support PHP image generation') ;

// clean up text
if(empty($_GET['text']))
    fatal_error('Error: No text specified.') ;
    
$text = $_GET['text'] ;
if(get_magic_quotes_gpc())
    $text = stripslashes($text) ;
$text = javascript_to_html($text) ;

// look for cached copy, send if it exists
$hash = md5(basename($font_file) . $font_size . $font_color .
            $background_color . $transparent_background . $text) ;
$cache_filename = $cache_folder . '/' . $hash . $extension ;
if($cache_images && ($file = @fopen($cache_filename,'rb')))
{
    header('Content-type: ' . $mime_type) ;
    while(!feof($file))
        print(($buffer = fread($file,$send_buffer_size))) ;
    fclose($file) ;
    exit ;
}

// check font availability
$font_found = is_readable($font_file) ;
if(!$font_found)
{
    fatal_error('Error: The server is missing the specified font.') ;
}

// create image
$background_rgb = hex_to_rgb($background_color) ;
$font_rgb = hex_to_rgb($font_color) ;
$dip = get_dip($font_file,$font_size) ;
$box = @ImageTTFBBox($font_size,0,$font_file,$text) ;
$image = @ImageCreate(abs($box[2]-$box[0])+20,abs($box[5]-$dip)+20) ;
if(!$image || !$box)
{
    fatal_error('Error: The server could not create this heading image.') ;
}

// allocate colors and draw text
$background_color = @ImageColorAllocate($image,$background_rgb['red'],
    $background_rgb['green'],$background_rgb['blue']) ;
$font_color = ImageColorAllocate($image,$font_rgb['red'],
    $font_rgb['green'],$font_rgb['blue']) ;   
ImageTTFText($image,$font_size,0,-$box[0]+10,abs($box[5]-$box[3])-$box[1]+10,
    $font_color,$font_file,$text) ;

// set transparency
if($transparent_background)
    ImageColorTransparent($image,$background_color) ;

header('Content-type: ' . $mime_type) ;
ImagePNG($image) ;

// save copy of image for cache
if($cache_images)
{
    @ImagePNG($image,$cache_filename) ;
}

ImageDestroy($image) ;
exit ;


/*
    try to determine the "dip" (pixels dropped below baseline) of this
    font for this size.
*/
function get_dip($font,$size)
{
    $test_chars = 'abcdefghijklmnopqrstuvwxyz' .
                  'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
                  '1234567890' .
                  '!@#$%^&*()\'"\\/;.,`~<>[]{}-+_-=' ;
    $box = @ImageTTFBBox($size,0,$font,$test_chars) ;
    return $box[3] ;
}


/*
    attempt to create an image containing the error message given. 
    if this works, the image is sent to the browser. if not, an error
    is logged, and passed back to the browser as a 500 code instead.
*/
function fatal_error($message)
{
    // send an image
    if(function_exists('ImageCreate'))
    {
        $width = ImageFontWidth(5) * strlen($message) + 10 ;
        $height = ImageFontHeight(5) + 10 ;
        if($image = ImageCreate($width,$height))
        {
            $background = ImageColorAllocate($image,255,255,255) ;
            $text_color = ImageColorAllocate($image,0,0,0) ;
            ImageString($image,5,5,5,$message,$text_color) ;    
            header('Content-type: image/png') ;
            ImagePNG($image) ;
            ImageDestroy($image) ;
            exit ;
        }
    }

    // send 500 code
    header("HTTP/1.0 500 Internal Server Error") ;
    print($message) ;
    exit ;
}


/* 
    decode an HTML hex-code into an array of R,G, and B values.
    accepts these formats: (case insensitive) #ffffff, ffffff, #fff, fff 
*/    
function hex_to_rgb($hex)
{
    // remove '#'
    if(substr($hex,0,1) == '#')
        $hex = substr($hex,1) ;

    // expand short form ('fff') color
    if(strlen($hex) == 3)
    {
        $hex = substr($hex,0,1) . substr($hex,0,1) .
               substr($hex,1,1) . substr($hex,1,1) .
               substr($hex,2,1) . substr($hex,2,1) ;
    }

    if(strlen($hex) != 6)
        fatal_error('Error: Invalid color "'.$hex.'"') ;

    // convert
    $rgb['red'] = hexdec(substr($hex,0,2)) ;
    $rgb['green'] = hexdec(substr($hex,2,2)) ;
    $rgb['blue'] = hexdec(substr($hex,4,2)) ;

    return $rgb ;
}


/*
    convert embedded, javascript unicode characters into embedded HTML
    entities. (e.g. '%u2018' => '&#8216;'). returns the converted string.
*/
function javascript_to_html($text)
{
    $matches = null ;
    preg_match_all('/%u([0-9A-F]{4})/i',$text,$matches) ;
    if(!empty($matches)) for($i=0;$i<sizeof($matches[0]);$i++)
        $text = str_replace($matches[0][$i],
                            '&#'.hexdec($matches[1][$i]).';',$text) ;

    return $text ;
}

?>

 
Odgovor na temu

semsudin
BIH

Član broj: 13751
Poruke: 58
*.asa.ba.

Sajt: www.hostbih.com


Profil

icon Re: PHP GD problem sa našim slovima12.09.2007. u 12:22 - pre 202 meseci
NPR: Umjesto slova š on mi ispiše u sličici kvadratić
Prikačeni fajlovi
 
Odgovor na temu

GxRxN

Član broj: 118184
Poruke: 25
*.eunet.yu.



Profil

icon Re: PHP GD problem sa našim slovima12.09.2007. u 22:48 - pre 202 meseci
Nedostaje ti meta-tag za utf-8 enkodiranje:
Code:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<form action="yuslova.php" method="GET">
  <input type="text" name="text">
  <button type="submit">send</button>
</form>


Bez te linije zahtev za ispisivanje slova š u firefox-u izgleda ovako:
Code:

?text=%9A

a treba ovako:
Code:

?text=%C5%A1

 
Odgovor na temu

semsudin
BIH

Član broj: 13751
Poruke: 58
*.asa-sped.ba.

Sajt: www.hostbih.com


Profil

icon Re: PHP GD problem sa našim slovima14.09.2007. u 06:56 - pre 202 meseci
Nema tu meta taga jer je sadrzaj koji se generise slika.

Usput rijesio sam problem, problem je bio što sam ja koristio jos jednu funkciju koju sam naprvio.
Ta funkcija je dodavala kerning, odnosno razmak izmedju slova.
Funkcija je unutar sebe koristila ugradjenu php funkciju str_split(), i upravo je to pravilo probleme.

str_split() rastavlja string po jedan bajt, pa je pogrešno rastavljala string. Problem je bio što sam ja koristio multibyte karaktere, kao što su naša slova čćžšđ.

Problem se riješi tako što se obične funkcije zamjene multibyte funkcijama i još naprave neke prilagodjene.

Rjesenje problema:

Code:

mb_internal_encoding("utf-8");

//multibyte str_replace funkcija
function mb_str_split($str, $length = 1)
{
    if ($length < 1) return FALSE;
    $result = array();
    for ($i = 0; $i < mb_strlen($str); $i += $length)
    {
        $result[] = mb_substr($str, $i, $length);
    }
    return $result;
}



Znaci samo koristiti mb_str_split umjesto str_split

 
Odgovor na temu

[es] :: PHP :: PHP GD problem sa našim slovima

[ Pregleda: 3187 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.