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.