M
M
Max Payne2015-02-08 20:18:23
PHP
Max Payne, 2015-02-08 20:18:23

How to save an image to a variable?

I use the following function to put text on an image:

function make_image($text,$font,$size) {
    $img = imagecreatefromjpeg('ui-bg-tile_1000_2.jpg'); 
    $color = imagecolorallocate ($img, 255, 255, 255);
    imagettftext($img, $size, 0, 10, 200, $color, $font, $text);
    imagejpeg($img);
    imagedestroy($img);
}

How to return the image code after executing the function in return? That is, to immediately return what will be in $return:
imagejpeg($img,'img.jpg'); $return = file_get_contents('img.jpg');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Ovchinnikov, 2015-03-26
@YardalGedal

ob_start();
imagejpeg($img);
$return = ob_get_contents();
ob_end_clean();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question