Note that there are some explanatory texts on larger screens.

plurals
  1. POimage editing function
    primarykey
    data
    text
    <p>I've created a function to overlay text onto images, but I'm scratching my head to find a way of outputting the image in a way in which it can be utilised within another script or outputted to the screen.</p> <p>I can call this function from a php script, passing it the image and the text to use, but when the function returns the data - it takes over the page due to the header - all I get as output is the image.</p> <p>I suspect this is an easy one and just shows a hole in my PHP knowledge - can someone set me straight here?</p> <p>Thanks!</p> <p>function makeimage($file, $text) { ob_start(); $x = getimagesize($file); $width = $x[0]; $height = $x[1]; $type = $x[2];</p> <pre><code> //header('Content-type: $type'); if ($type == 1) { $im = imagecreatefromgif($file); } elseif ($type==2) { $im = imagecreatefromjpeg($file); } elseif ($type==3) { $im = imagecreatefrompng($file); } // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); // Replace path by your own font path $font = 'arial.ttf'; // Add some shadow to the text imagettftext($im, 20, 0, 11, 21, $grey, $font, $text); // Add the text imagettftext($im, 20, 0, 10, 20, $black, $font, $text); ob_clean(); //to be sure there are no other strings in the output buffer imagepng($im); $string = ob_get_contents(); ob_end_clean(); return $string; </code></pre> <p>}</p> <p>I want to create this image, and then have it outputted in such a way as I can display it on screen in amongst all the other output.</p>
    singulars
    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.
    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