Mount an image from other images with PHP

0

Hello;

I wonder if I can mount an image from other images sequentially.

For example: Let's say that I have a word and image register defined for each letter of the alphabet. When registering a word, Bee for example, I want to create an image from 6 images (A B E L H A). Obs: I do not want to give an imagecreate from a string, I want to create from already defined images.

Solution

$string = "ABELHA";
$len = strlen($string);
$im = imagecreatetruecolor( 60 * $len, 60 );
for( $i = 0; $i < $len; ++$i ) {
    $letra = substr( $string, $i, 1 );
    $lim= imagecreatefrompng("./$letra.png");
    imagecopy ( $im, $lim, $i * 60, 0, 0, 0, 60, 60 );
    imagedestroy( $lim );
}
header('Content-Type: image/jpeg');
imagejpeg( $im );
imagedestroy( $im );
    
asked by anonymous 29.08.2016 / 18:58

1 answer

2

Your question is a bit broad, but it follows a code base:

Suppose the letters are 60 × 60px in size and saved as A.png , B.png etc.

$string = 'ABELHA';
$len = count( $string );
$im = imagecreatetruecolor( 60 * $len, 60 );
for( $i = 0; $i < $len; ++$i ) {
   $letra = ( $string, $i, 1 );
   $lim= imagecreatefrompng("/caminho/$letra.png");
   imagecopy ( $im, $lim, $i * 60, 0, 0, 0, 60, 60 );
   imagedestroy( $lim );
}
imagejpeg( $im );
imagedestroy( $im );

I focused on the question problem, I did not consider encoding and accent problems, nor special characters to not overextend.

To use other characters other than numbers and from A to Z, you have to treat the string as you see fit.

    
29.08.2016 / 19:13