Create an image in PHP & and add image?

  • RedBMedia
  • Proficient
  • Proficient
  • User avatar
  • Posts: 315

Post 3+ Months Ago

Hello All

I am trying to create an image in PHP with the imagecreate() function. I am wondering if it is possible for a user to upload an image like their logo and use that in the image that I am creating? I know that one can use a preexisting image with the imagecreatefrompng() function, but I am interested in adding an image to the imagecreate().

Below is my code:

Code: [ Select ]
<?php
$my_img = imagecreate( 200, 80 );
$background = imagecolorallocate( $my_img, 0, 0, 255 );
$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
imagestring( $my_img, 4, 30, 25, "thesitewizard.com",
$text_colour );
imagesetthickness ( $my_img, 5 );
imageline( $my_img, 30, 45, 165, 45, $line_colour );

header( "Content-type: image/png" );
imagepng( $my_img );
imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );
?>
  1. <?php
  2. $my_img = imagecreate( 200, 80 );
  3. $background = imagecolorallocate( $my_img, 0, 0, 255 );
  4. $text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
  5. $line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
  6. imagestring( $my_img, 4, 30, 25, "thesitewizard.com",
  7. $text_colour );
  8. imagesetthickness ( $my_img, 5 );
  9. imageline( $my_img, 30, 45, 165, 45, $line_colour );
  10. header( "Content-type: image/png" );
  11. imagepng( $my_img );
  12. imagecolordeallocate( $line_color );
  13. imagecolordeallocate( $text_color );
  14. imagecolordeallocate( $background );
  15. imagedestroy( $my_img );
  16. ?>


Any thoughts?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Once you're sure the uploaded file is safe to work with, you determine what type of image it is, then use the "imagecreatefrom*" function for that type pointing to the path of the uploaded file.

That will give you an image resource you can copy to $my_img using imagecopy, imagecopyresampled, etc.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 93 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.