Note that there are some explanatory texts on larger screens.

plurals
  1. POget <img> tag from @imagecreatefromjpeg?
    primarykey
    data
    text
    <p>I am writing text over image using PHP.I am easily creating new image from current image and writing text over it using PHP.But I also want that when I click on Apply Changes then move this new image to my directory (move_uploaded_file) and replace the current image with the new image and new image name must be the same of the previous image because I am downloading it using PHP.</p> <p>Here is my code which I am using to wrote text over it.</p> <p><strong>HTML code :</strong> </p> <pre><code> &lt;img id="image" src="&lt;?php echo "upload_pic/" . $_FILES["image_file"]["name"]; ?&gt;" alt="your_image" /&gt; &lt;input type="button" name="save_image" id="save_image" value="Save Image" /&gt; &lt;input type="hidden" id="hidden_image_name" name="hidden_image_name" value="&lt;?php echo $_FILES["image_file"]["name"]; ?&gt;" /&gt; </code></pre> <p><strong>jQuery Code :</strong></p> <pre><code>jQuery('#save_image').click(function(){ var image_name = jQuery('#hidden_image_name').val(); jQuery.ajax({ url:'text_image.php', data:'file='+image_name, type:'get', success:function(data){ alert(data); } }); }); </code></pre> <p><strong>text_image.php</strong></p> <pre><code>&lt;?php $file = 'upload_pic/'.$_GET['file']; /*** set the header for the image ***/ header("Content-type: image/jpeg"); /*** specify an image and text ***/ $im = writeToImage($file, 'PHPRO rules again'); //echo $im; /*** spit the image out the other end ***/ imagejpeg($im); /** * * @Write text to an existing image * * @Author Kevin Waterson * * @access public * * @param string The image path * * @param string The text string * * @return resource * */ function writeToImage($imagefile, $text){ /*** make sure the file exists ***/ if(file_exists($imagefile)) { /*** create image ***/ $im = @imagecreatefromjpeg($imagefile); /*** create the text color ***/ $text_color = imagecolorallocate($im, 233, 14, 91); /*** splatter the image with text ***/ imagestring($im, 6, 25, 150, "$text", $text_color); } else { /*** if the file does not exist we will create our own image ***/ /*** Create a black image ***/ $im = imagecreatetruecolor(150, 30); /* Create a black image */ /*** the background color ***/ $bgc = imagecolorallocate($im, 255, 255, 255); /*** the text color ***/ $tc = imagecolorallocate($im, 0, 0, 0); /*** a little rectangle ***/ imagefilledrectangle($im, 0, 0, 150, 30, $bgc); /*** output and error message ***/ imagestring($im, 1, 5, 5, "Error loading $imagefile", $tc); } return $im; } ?&gt; </code></pre> <p>Thanks in Advanced!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload