php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62961 please add exif_imagetypefromstring
Submitted: 2012-08-29 01:02 UTC Modified: 2012-08-29 17:22 UTC
From: scott dot jungwirth at demandmedia dot com Assigned:
Status: Closed Package: EXIF related
PHP Version: 5.3.16 OS: CentOS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
18 + 10 = ?
Subscribe to this entry?

 
 [2012-08-29 01:02 UTC] scott dot jungwirth at demandmedia dot com
Description:
------------
It would be nice to have an exif_imagetypefromstring function to determine an 
image type from a string without having to save the string to a file in order to 
use the exif_imagetype function.

There is a getimagesizefromstring function in PHP 5.4 but exif_imagetype is 
supposed to be much faster as it only needs to look at the first couple of bytes 
of the string to determine the image type. 

My problem is I can't really take advantage of the faster behavior because my 
image data is in a string, not in a file.

Test script:
---------------
<?php
$extension = image_type_to_extension(exif_imagetypefromstring($bin_data));

// versus

$tmpfile = tempnam('/tmp', 'upload');
file_put_contents($tmpfile, $bin_data);
$extension = image_type_to_extension(exif_imagetype($tmpfile));
unlink($tmpfile);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-29 09:29 UTC] laruence@php.net
hmm, how about (rfc 2397):
$extension = image_type_to_extension(exif_imagetype("data://image/;base64," . 
base64_encode($bin_data)));
 [2012-08-29 17:22 UTC] scott dot jungwirth at demandmedia dot com
-Status: Open +Status: Closed
 [2012-08-29 17:22 UTC] scott dot jungwirth at demandmedia dot com
That seems to work, I was not familiar with this method. I will use that since I 
don't even need to update my PHP version. Thanks!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 17:01:29 2024 UTC