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

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top