Pergunta

What function should I use to get file content (jpg) from variable which comes from:

 $filename = 'temporary.jpg';
 $percent = 2.5;
 list($width, $height) = getimagesize($filename);
 $newwidth = $width * $percent;
 $newheight = $height * $percent;
 $thumb = imagecreatetruecolor($newwidth, $newheight);
 $source = imagecreatefromjpeg($filename);    
 imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

To be more specific I'm talking about $thumb variable which is image. I want do this to unpack this data, and then send to DB

Foi útil?

Solução

Image storing functions like imagejpeg() output the data to the browser by default. You can capture that and save it into a variable like so:

ob_start();
imagejpeg($thumb);
$thumbData = ob_get_clean();

Then insert that to the database as any other (binary) string.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top