Jump to content

Creating an Image in PHP: I need larger text!


ivoilic

Recommended Posts

Hello Forums,

So basically I am trying to place text over an image.

It works but the max text size is 5 which is way too small for my needs!

What can I do to increase the size of the text?  :confused:

If anyone can help it would be much appreciated.

:)

Here is my code:

<?php
  $title = $_REQUEST['title'] ;   
$my_img = imagecreatefrompng ( "Template.png" );
$text_color = imagecolorallocate( $my_img, 0, 0, 0 );
imagestring( $my_img, 5, 30, 25, "$title",
  $text_colour );
header( "Content-type: image/png" );
imagepng( $my_img );
imagecolordeallocate( $text_color );
imagedestroy( $my_img );
?>

 

Thanks litebearer! :)

Well I got my solution from a tutorial so I will just post a link to it.  I just took the same code with some slight modifications to fit my specific needs. http://www.phpfreaks.com/tutorial/php-add-text-to-image

If anyone can still help me with combining images it would be a huge help! :D

Thank you for the link blacknight, but that is not exactly what I was talking about.  I am trying to set something up where a user could go to my site enter text and upload a picture which would then be combined with a background image.  I have the text part down:

$image = imagecreatefrompng ( "Templates/template.png" );
// Path to our font file
$font = 'MJoa';
$italic = 'MJoaIta';
// pick color for the text
$fontcolor = imagecolorallocate($image, 0, 0, 0);

//Create Title
imagettfbbox(35, 0, $font, $title);
imagettftext($image, 35, 0, 40, 80, $fontcolor, $font, stripslashes($title));

What I need is some way of placing one image over another and then flattening it.

essentially take image1, add text to create image2, take image2 and overlay it on image2

 

Copy a part of src_im onto dst_im starting at the x,y coordinates src_x, src_y with a width of src_w and a height of src_h. The portion defined will be copied onto the x,y coordinates, dst_x and dst_y.

 

See blacknight's link -

 

this is the function i use to combine images

function combineImage( $image,$filename,$x_loc,$y_loc )
{
	$info = getimagesize($filename);

	switch( $info['mime'] )
	{
		case 'image/jpeg' :
			$im_temp = @imagecreatefromjpeg($filename);
			break;

		case 'image/png' :
			$im_temp = @imagecreatefrompng($filename);
			break;

		case 'image/gif' :
			$im_temp = @imagecreatefromgif($filename);
			break;

		default:
			debugMode( $line,'Unhandled image type: ' . $info['mime'] );
	}

	// Get the image dimentions
	$im_temp_width = imageSX( $im_temp );
	$im_temp_height = imageSY( $im_temp );

	// Copy created image into main image
	@imagecopy( $image,$im_temp,$x_loc,$y_loc,0,0,$im_temp_width,$im_temp_height );

	// Destroy the temp image
	if( isset($im_temp) )
	{
		@imageDestroy( $im_temp );
	}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.