Jump to content

Image creation


steveangelis

Recommended Posts

I am attempting to create an image and I have run into a snag.  I want to add both text and another image to the image I am making.  Here is the code so far minus unnecessary parts:

 

header ("Content-type: image/png");

$name = $fetch_user['username'];

$rank = $fetch_rank['rank_title'];

$img_url = 'path''. $fetch_rank['rank_image'];

$im = @imagecreatefrompng("$img_url")

or die("Cannot Initialize new GD image stream");

// try changing this as well

$font = 4;

$width = imagefontwidth($font) * strlen($string) ;

$height = imagefontheight($font) ;

$im = imagecreatefrompng("image.png");

$x = imagesx($im) - $width ;

$y = imagesy($im) - $height;

$backgroundColor = imagecolorallocate ($im, 255, 255, 255);

$textColor = imagecolorallocate ($im, 255, 255, 255);

//imagestring ($im, $font, $x, $y,  $string, $textColor);

imagestring ($im, $font, 100, 10,  $name, $textColor);

imagestring ($im, $font, 100, 22,  $rank, $textColor);

imagepng($im);

 

Everything works UNTIL I added in this part:

 

$im = @imagecreatefrompng("$img_url")

or die("Cannot Initialize new GD image stream");

 

Any idea what I am doing wrong? All that comes up is "Cannot Initialize new GD image stream"; and I know the URL's work.

Link to comment
Share on other sites

This has been tested and works.

Make appropriate modifications for your particular use.

<?PHP
header ("Content-type: image/png");
/* IMAGE TO USE AS BACKGROUND */
$source_image = "road000.png"; 

/* IMAGE TO OVERLAY ON BACKGROUND */
$overlay_image = "road001.png";

/* CREATE TEMPORARY BACKGROUND */
$background = imagecreatefrompng($source_image);

/* CREATE TEMPORARY OVERLAY IMAGE */
$insert = imagecreatefrompng($overlay_image); 

/* GET OVERLAY IMAGE WIDTH AND HEIGHT */
$insert_x = imagesx($insert); 
$insert_y = imagesy($insert); 

/* SET WHERE YOU WANT TO PLACE OVERLAY ON BACKGROUND */
/* FOR THIS EXAMPLE WE WILL USE 100 FROM LEFT AND TOP EDGES */
$set_x = 100;
$set_y = 100;

/* COMBINE THE IMAGES INTO A SINGLE OUTPUT IMAGE */
imagecopymerge($background,$insert,$set_x,$set_y,0,0,$insert_x,$insert_y,100); 

/* OUTPUT THE RESULTS */
imagepng($background); 

?>

Link to comment
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.