如何将文本数据转换为jpeg格式图像?

时间:2014-07-25 17:41:41

标签: php image

我是php的新手,所以请免除我的错误。

我从网站下载图像文件也使用它与ocr但是当我从网站下载图像文件时,我得到一个php文件,我必须首先将扩展名更改为.jpeg,然后使用它转换为图像转换器与ocr一起使用我想知道有没有办法我可以使用php转换为jpeg格式,以便与ocr一起使用。我尝试了其他问题及其答案中列出的几种方法,但它们不起作用,它们返回一个不可读的,我甚至无法在Windows中查看。

以下是示例图片: http://www.datafilehost.com/d/2bc5fcd5

以下是php转换的示例图片: http://www.datafilehost.com/d/a1c902fb

这是我用来将php文件转换为图像的代码:

global $buf;

$imagepath = 'securimage_show.php';
$imagedata = GetFileData($imagepath);

ob_start();
$length = strlen($imagedata);
header('Last-Modified: '.date('r'));
header('Accept-Ranges: bytes');
header('Content-Length: '.$length);
header('Content-Type: image/jpeg');
print($imagedata);
ob_end_flush();
/*======FUNCTIONS USED======*/
function GetFileData($imagepath){
    $fp = fopen($imagepath, 'rb') or die('404! Unable to open file!');
    $buf = '';
    while(!feof($fp)){
        $buf .= fgets($fp, 4096);
    }
    fclose($fp);
return $buf; //returns False if failed, else the contents up to FileSize bytes.
}
    $imag = imagejpeg($buf);
    file_put_contents("qeqxcxew.jpg", $imag);

当代码在浏览器中输出时,我可以在浏览器中查看图像,所以我假设我在保存文件时出错。请帮忙

由于

阿卡什

0 个答案:

没有答案