Jump to content

Recommended Posts

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)

Link to comment
https://forums.phpfreaks.com/topic/181054-imagecreate/#findComment-955312
Share on other sites

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.

83559779.png

Link to comment
https://forums.phpfreaks.com/topic/181054-imagecreate/#findComment-955321
Share on other sites

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);
?>

Link to comment
https://forums.phpfreaks.com/topic/181054-imagecreate/#findComment-955355
Share on other sites

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).

Link to comment
https://forums.phpfreaks.com/topic/181054-imagecreate/#findComment-955381
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.