Php ile yazıyı resme çevirmek
Merhaba arkadaşlar , bu konuda sizlere php ile bir text i nasıl resim haline çevirceğimizi anlatıcam ..
Uygulamanın adı Text to image öncelikle 3 adet dosyamız var ;
1.text2image.php
2.image_functions.php
3.comic.ttf
Text2image.php dosyası işlemin gerçekleşip ekrana çıkartığı dosyadır , image_functions.php dosyası ise ismindende anlaşıldığı gibi fonksiyonların olduğu dosya ve comic.ttf dosyası ise font dosyamız yani text in hangi font la yazılcağını belirliyoruz .
Text2image.php
-
-
$text = " Deneme 123 , iyi sahurlar perfectgate ailesi .";
-
$req_height = 1;
-
$width = 400;
-
-
// grab font
-
$font = FONT_DIR . '/comic.ttf';
-
-
// black and white here
-
-
-
$textSize = 10;
-
$angle = 0;
-
$top = 10;
-
$left = 0;
-
$right = $width;
-
// ImageTTFText( $image, $size, $angle, $top, $left, $text_color, $font , $description );
-
-
$height = imageprintWordWrapped(&$image, $top, $left, $right, $font, $color, $text, $textSize, $halign="left") ;
-
-
if( $height> $req_height )
-
{
-
imageprintWordWrapped(&$image, $top, $left, $right, $font, $color, $text, $textSize, $halign="left") ;
-
-
}
-
-
-
?>
Image_functions.php
-
-
//
-
//
-
-
function imageprintWordWrapped(&$image, $top, $left, $right, $font, $color, $text, $textSize, $halign="left")
-
{
-
$maxWidth = $right - $left ; //the trivial change
-
$line = '';
-
$dimensions = imagettfbbox($textSize, 0, $font, $line.' '.$words[0]);
-
$lineWidth = $dimensions[2] - $dimensions[0]; // get the length of this line, if the word is to be included
-
if ($lineWidth> $maxWidth) { // if this makes the text wider that anticipated
-
$lines[] = $line; // add the line to the others
-
$line = ''; // empty it (the word will be added outside the loop)
-
}
-
$line .= ' '.$words[0]; // add the word to the current sentence
-
}
-
if ($line != '') { $lines[] = $line; } // add the last line to the others, if it isn't empty
-
-
// aded some paddding in th eling height
-
$lineHeight = 1.5 * ( $dimensions[1] - $dimensions[7] ); // the height of a single line
-
-
// do the actual printing
-
$i = 1;
-
//print_R($widths);
-
foreach ($lines as $line) {
-
if($halign=="center") {
-
//figure out width of line
-
$dimensions = imagettfbbox($textSize, 0, $font, $line);
-
$lineWidth = $dimensions[2] - $dimensions[0];
-
//figure out where the center is.
-
$leftStart=$center-$lineWidth/2;
-
} else if ($halign=="right") {
-
//figure out width of line
-
$dimensions = imagettfbbox($textSize, 0, $font, $line);
-
$lineWidth = $dimensions[2] - $dimensions[0];
-
$leftStart=$left+$maxWidth-$lineWidth;
-
} else {
-
$leftStart=$left;
-
}
-
$i++;
-
}
-
return $height;
-
}
-
-
?>

Resmi PNG formatında kaydediyor.
Üst üste mesaj olarak algılanmasın ama düzenle botunu belirli bir süreden sonra yok oluyor , Kodun gerçek kaynağı burasımı değil ama ona benzer bir uygulama var burda ve büyük ihtimalle bu kodda php classes den çıkmıştır .
Kaynak : http://www.phpclasses.org/browse/package/2349.html
Benzer Yazılar
Yorum Yap
XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

26 Eylül 2007 |



Etiketler:

