kkkaiden Posted November 11, 2009 Share Posted November 11, 2009 When I create an image and add text to it I want my text to be replaced with a PNG image, because the PNG image has text effects. I have an image of every letter I just don't know if this is possible or how to do it, can someone help please? Quote Link to comment https://forums.phpfreaks.com/topic/181054-imagecreate/ Share on other sites More sharing options...
Alex Posted November 11, 2009 Share Posted November 11, 2009 Is it just a special font? Why not just use imagettftext() or imageloadfont(). Technically you can use your custom image, pretty easily, but it'll be pretty slow. Quote Link to comment https://forums.phpfreaks.com/topic/181054-imagecreate/#findComment-955310 Share on other sites More sharing options...
MadTechie Posted November 11, 2009 Share Posted November 11, 2009 If its just an effect it will be quicker to create or get a custom font..if the letter are out the scoop of a normal font (it colours etc) then you will need to use something like imagecopy basically you add an image on top of another time, I'll suggest you name all of the files to the same as the image letter. it A.png = the image of the letter A etc etc Then create or load the background image as the destination image, then do something like this 1. (prep) $x=0;$gap=1;breakup string into letters (array) 2. get the width of the image letter (used later) getimagesize ($last_width) 3. load letter image as source imagecreatefrompng 4. put destination image on source image, (dst_x = $x) 5. $x=$x+$last_width+$gap; 6. goto 2. (repeat with all letters) Quote Link to comment https://forums.phpfreaks.com/topic/181054-imagecreate/#findComment-955312 Share on other sites More sharing options...
kkkaiden Posted November 11, 2009 Author Share Posted November 11, 2009 Thanks for the speedy posts, but i don't know what you mean. I'm using this code: <?php header("content-type: image/png"); $height = 283; $width = 718; $fontsize = 130; $text = $_GET['text']; $bg = $_GET['background']; $image = imagecreatefrompng("images/$bg.png"); $color = imagecolorallocate( $image, 255, 215, 50); $font = "LifeCraft.ttf"; $textwidth = $width; $textheight; while ( true ) { $box = imageTTFbbox ( $fontsize, 2, $font, $text ); $textwidth = abs( $box[2] ); $textbodyheight =( abs($box[7]) )+55; if ( $textwidth < $width - 20 ) break; $fontsize--; } $pngXcenter = (int) ( $width/2 ); $pngYcenter = (int) ( $height/2 ); imageTTFtext( $image, $fontsize, 0, (int) ($pngXcenter-($textwidth/2)), (int) ($pngYcenter+(($textbodyheight)/2) ), $color, $font, $text ); imagepng($image); ?> I want my normal text to be an image. Quote Link to comment https://forums.phpfreaks.com/topic/181054-imagecreate/#findComment-955321 Share on other sites More sharing options...
MadTechie Posted November 11, 2009 Share Posted November 11, 2009 okay forget the writing text to the image, what you need to do is place images on top of images. what part is unclear ? Quote Link to comment https://forums.phpfreaks.com/topic/181054-imagecreate/#findComment-955343 Share on other sites More sharing options...
kkkaiden Posted November 11, 2009 Author Share Posted November 11, 2009 The part that is unclear is getting the images ontop of the image i already have. Quote Link to comment https://forums.phpfreaks.com/topic/181054-imagecreate/#findComment-955345 Share on other sites More sharing options...
MadTechie Posted November 11, 2009 Share Posted November 11, 2009 To do that see imagecopy in the manual, it has examples here's an example (untested) but should help you on your way.. (of course your need a.png and b.png) and it assumes the hight is 50px (if its bigger change the 50's to whatever (you may also want to change the 200 to a larger number) <?php //Blank image $dest = imagecreatetruecolor(200, 50); $gap = 2; $X = 0; //get Letter A $src = imagecreatefrompng('a.png'); getimagesize('a.png',$info); //Put image letter A on Blank Image imagecopy($dest, $src, 0, 0, $X, 0, $info[0], 50); imagedestroy($src); //Next letter $X = $X+$info[0]+$gap; //get Letter B $src = imagecreatefrompng('b.png'); getimagesize('b.png',$info); //Put image letter B on Blank Image imagecopy($dest, $src, 0, 0, $X, 0, $info[0], 50); imagedestroy($src); //done display image // Output and free from memory header('Content-Type: image/png'); imagegif($dest); imagedestroy($dest); ?> Quote Link to comment https://forums.phpfreaks.com/topic/181054-imagecreate/#findComment-955355 Share on other sites More sharing options...
kkkaiden Posted November 11, 2009 Author Share Posted November 11, 2009 how would i use that on this code? <?php header("content-type: image/png"); $height = 283; $width = 718; $fontsize = 130; $text = $_GET['text']; $bg = $_GET['background']; $image = imagecreatefrompng("images/$bg.png"); $color = imagecolorallocate( $image, 255, 215, 50); $font = "LifeCraft.ttf"; $textwidth = $width; $textheight; while ( true ) { $box = imageTTFbbox ( $fontsize, 2, $font, $text ); $textwidth = abs( $box[2] ); $textbodyheight =( abs($box[7]) )+55; if ( $textwidth < $width - 20 ) break; $fontsize--; } $pngXcenter = (int) ( $width/2 ); $pngYcenter = (int) ( $height/2 ); imageTTFtext( $image, $fontsize, 0, (int) ($pngXcenter-($textwidth/2)), (int) ($pngYcenter+(($textbodyheight)/2) ), $color, $font, $text ); imagepng($image); ?> I want it to replace for example: the letter 'a' int my $text variable with an image (a.png). Quote Link to comment https://forums.phpfreaks.com/topic/181054-imagecreate/#findComment-955381 Share on other sites More sharing options...
MadTechie Posted November 11, 2009 Share Posted November 11, 2009 same logic, just replace $box = imageTTFbbox ( $fontsize, 2, $font, $text ); with a function that breaks the string up into letters then runs a loop using something close to my last post Quote Link to comment https://forums.phpfreaks.com/topic/181054-imagecreate/#findComment-955391 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.