简体   繁体   English

旋转base 64映像并作为BLOB插入MySql

[英]Rotate base 64 image and insert into MySql as BLOB

I am just trying to rotate the image coming from the DB, which is base 64 format. 我只是想旋转来自数据库的图像,该图像是基本64格式。 and update back the rotated image into mysql. 并将更新后的映像更新回mysql。

My Image 我的形象

$imageData=mysql_real_escape_string($rs[0]['image_data']);// base 64 format
$degrees = 180;

rotate image function 旋转影像功能

    ob_start();
    $destImage = imagerotate($imageData, $degrees, 0) ;     
    imageJPEG($destImage);
    $image_thumb =mysql_real_escape_string(ob_get_contents());
    ob_end_clean();

The control is not going inside ob_start(). 控件不在ob_start()内部。 Please help 请帮忙

You don't want to escape the data you read from the DB, you only escape it when you write it. 您不想转义从数据库读取的数据,而只在写数据时转义。 The raw data isn't an image resource: 原始数据不是图像资源:

$imageData = $rs[0]['image_data'];
$im = imagecreatefromstring($data);

$degrees = 180;

ob_start();
$destImage = imagerotate($im, $degrees, 0) ;     
imageJPEG($destImage);
$image_thumb =mysql_real_escape_string(ob_get_contents());
ob_end_clean();

The other thing you might need to add is decode/encode for base64. 您可能需要添加的另一件事是对base64进行解码/编码。 Easier to store as a blob that way. 这样更容易存储为Blob。 otherwise you are escaping a binary string which could be a problem. 否则,您将转义二进制字符串,这可能是一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM