The renderImage function we’ll be creating needs to start with the supplied background image. Then it should add the user’s avatar and the text of their latest Twitter status. This should be finalized into an image and served to the browser. Let’s look at the code to do that. private function renderImage($bg_image) { if ( !function_exists('gd_info') ) { // No GD support. } $margin_left = 11; $margin_bottom = 6; $image = @imagecreatefromjpeg($bg_image); if (!$image) { // Unable to create image. } $this->embedAvatar($image, $this->local_avatar, $margin_left, $margin_bottom); $string = "{$this->screen_name}: {$this->status_text}"; $this->embedText($image, $string, $margin_left, $margin_bottom); header("Content-type: image/jpeg"); $created = @imagejpeg($image); if (!$created) { // Unable to finalize image. } @imagedestroy($image); } If you’ve ever used GD to create dynamic images in the past, this should look pretty familiar to you. The ImageCreateFromJpeg function is used to create an image from a background. Then we make calls to two custom functions, embedAvatar and embedText, to add the user’s avatar and status text to the image. The image is then finalized with the ImageJpeg function, which creates and outputs a JPEG image. Notice that I also perform a little cleanup with the ImageDestroy function before ending my method.
blog comments powered by Disqus |
|
|
|
|
|
|
|