mySQL / PHP で画像を処理する関数を作成しようとしていますが、結果を保存する方法がわかりません。問題を示すために、コードの簡略化されたバージョンを含めました。
image.image_o のブロブはすべて正しく保存され、Web ページに画像を出力するために使用できます。関数はエラーなしで実行されますが、その後、image.image_r のブロブの長さはほんの数バイトで、「Resource id #5」のようなテキストが含まれています。
私はばかげたことをしていると確信しています-それが何であるかがわかりません。
function process_images(){
global $mysql
$sql = "select id, image_o from image";
$res = mysqli_query($mysqli, $sql);
if ($res){
while ($ay = mysqli_fetch_array($res, MYSQLI_ASSOC)){
$id = $ay['id'];
$im = imagecreatefromstring($ay['image_o']);
// do something useful with the image
$sql2 = "update image set image_r = '{$im}' where id = $id";
$res2 = mysqli_query($mysqli, $sql2);
if ($res2){
// blah blah
}else{
echo mysqli_error($mysqli)." in res2";
}
}
}else{
echo mysqli_error($mysqli)." in res";
}
}