1

I have been working on a project trying to write text to an image using php gd library. I have succeeded in generating the image and outputing it to the browser. What I want to know is... is there a way I could get the image to popup on the same page without loading and displaying the image in the php file that contains the code for creating and writing text to the image? Thanks in advance for your help.

My code:

<?php 

//Set content type
header('Content-type: image/jpeg');

// Create image from existing image
$jpgImage = imagecreatefromjpeg('file.jpg');

// Allocate color for text
$white = imagecolorallocate($jpgImage, 255, 255, 255);

// Set Path to Font File
$font = 'arialbd.ttf';

// Text to print to image
$text = 'Testing text output';

// Print Text On Image
imagettftext($jpgImage, 75, 0, 50, 400, $white, $font, $text);



// Send Image to Browser
imagejpeg($jpgImage);

// Clear Memory
imagedestroy($jpgImage);

?> 

Can Bootstrap 3 be used to accomplish this task? Thank you

HazardPJ
  • 25
  • 7
  • 1
    If you use AJAX you can get JavaScript (jQuery for Bootstrap I believe?) to receive the newly created image URL and your AJAX "on complete" listener can create a popup and use the returned URL as the source. Use answer here as a starting point for Bootstrap: http://stackoverflow.com/questions/18220462/how-to-show-a-url-in-bootstrap-modal-dialog-on-button-click – Kinnectus Jan 13 '15 at 16:05
  • pass this script as src to image tag – charlietfl Jan 13 '15 at 16:05
  • No Big Chris, I dont use AJAX but I'll look through the link you sent. @charlietfl I tried that but it unfortunately didn't work – HazardPJ Jan 13 '15 at 17:16
  • tried it how? If php outputs to browser should also work as src for `` – charlietfl Jan 13 '15 at 17:52
  • by replacing `src` of `` with the php file containing the imagecreate() code. – HazardPJ Jan 13 '15 at 20:40
  • @charlietfl since the image is not saved to the server, I want it to be sent to the browser and the modal simultaneously, thereby not showing the image in the browser but it'll be sent straight to the modal. Thanks. – HazardPJ Jan 13 '15 at 21:16
  • that's the whole point of putting it in an image tag pointed at your php script. Or could create image in browser using base64 data via ajax – charlietfl Jan 13 '15 at 22:27
  • @charlietfl I haven't learn ajax yet – HazardPJ Jan 14 '15 at 19:24
  • I'll let you know if it succeeds – HazardPJ Jan 14 '15 at 19:25

0 Answers0