如何处理图像的哑剧类型“应用程序/八位字节流"? [英] how handling image's mime type "application/octet-stream"?

查看:117
本文介绍了如何处理图像的哑剧类型“应用程序/八位字节流"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能可以动态制作网址图像的缩略图! 我总是将jpg类型的图像传递给该函数,但是当我传递扩展名为".jpg"的图像时会出现问题.但是,当我尝试获取其mime类型时,在此application/octet-stream ".. image-type-to-mime-type.php"rel =" noreferrer> php页面,此mime类型是指其中一种

I have a function to make thumbnail of a url image on fly! I always pass to this functions images with type jpg, but the problem appears when I pass an image with ".jpg" extension. but when i try to get its mime type, i found that's "application/octet-stream" .. in this php page, this mime type refers to one of

IMAGETYPE_JPC,IMAGETYPE_JPX,IMAGETYPE_JB2

IMAGETYPE_JPC,IMAGETYPE_JPX,IMAGETYPE_JB2

我需要修改我的函数来处理这种mime类型吗?

what I need to modify my function to handle this mime type ??

通知^^^^^^

function thumb($path,$width,$height) // $path => image url
{
        $file_dimensions = getimagesize($path);
        $file_type = image_type_to_mime_type($file_dimensions[2]);
        list($Cwidth, $Cheight) = getimagesize($path);
        if ($file_type=='image/jpeg'||$file_type=='image/pjpeg'){
            // Load
        $thumb = imagecreatetruecolor($width, $height);
        $source = imagecreatefromjpeg($path);
        // Resize
        imagecopyresized($thumb, $source, 0, 0, 0, 0, $width, $height, $Cwidth, $Cheight);
        header('Content-Type: image/jpeg');
        imagejpeg($thumb);
        }
        else if ($file_type=='application/octet-stream')
        {
           // ^^^^^ what I should write here
        }
        else
        {
            echo "Not supported type";
        } 
} 

推荐答案

我刚才正在处理同一件事.

I'm working around the same thing just now.

我正在使用finfo测试一些图像,.gif,.jpeg,.png ...,我发现读取的mime类型取决于读取文件的常量.更多的!您可以从图像中读取应用程序/八位字节流作为模仿类型!而且该信息没有错. 请参阅:

I was testing some images, .gif, .jpeg, .png ... using finfo I found the mime-type you read depends on the constants you use to read the file. More! You read application/octet-stream as mimetype from images! and that info is not wrong. See:

如果使用不带常量的finfo_open():

If you use finfo_open() without constants:

<?php
$finfo = finfo_open();
$FileInfo = finfo_file($finfo, $tmp_name);
finfo_close($finfo);

您将获得所需的哑剧类型:

You get the mime type you expect:

如果是.svg-> HTML文档,则是ASCII文本,具有很长的行,没有行终止符

If .svg -> HTML document, ASCII text, with very long lines, with no line terminators

如果是.jpg(来自手机相机)-> JPEG图像数据,EXIF标准2.2

If .jpg (from your phone camera) -> JPEG image data, EXIF standard 2.2

如果.gif(从涂料保存)-> GIF图像数据,版本89a,宽x高

If .gif (saved from paint) -> GIF image data, version 89a, w x h

同时使用诸如FILEINFO_MIME_TYPE之类的常量

while using a constant like FILEINFO_MIME_TYPE

<?php
$finfo = finfo_open(FILEINFO_MIME_TYPE, $mf); // $mf is a magic file
$FileInfo = finfo_file($finfo, $tmp_name);
finfo_close($finfo);

您获得了不同的价值:

如果.svg->文本/纯文本

if .svg -> text/plain

如果.jpg(来自您的手机摄像头)-> application/octet-stream

if .jpg (from your phone camera) -> application/octet-stream

如果.gif(从绘画保存)-> application/octet-stream

if .gif (saved from paint) -> application/octet-stream

因此,在测试模仿类型时,您必须测试所读内容.请参见 Fileinfo预定义常量

So you must test what you read when testing mimetypes. See Fileinfo Predefined constants

希望有帮助

这篇关于如何处理图像的哑剧类型“应用程序/八位字节流"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆