Changeset 4324 in subversion


Ignore:
Timestamp:
Dec 8, 2010 3:36:08 PM (2 years ago)
Author:
thomasb
Message:

Move image type detection to shared function

Location:
branches/devel-addressbook/program
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-addressbook/program/include/rcube_shared.inc

    r4177 r4324  
    486486} 
    487487 
     488 
     489/** 
     490 * Detect image type of the given binary data by checking magic numbers 
     491 * 
     492 * @param string  Binary file content 
     493 * @return string Detected mime-type or jpeg as fallback 
     494 */ 
     495function rc_image_content_type($data) 
     496{ 
     497    $type = 'jpeg'; 
     498    if      (preg_match('/^\x89\x50\x4E\x47/', $data)) $type = 'png'; 
     499    else if (preg_match('/^\x47\x49\x46\x38/', $data)) $type = 'gif'; 
     500    else if (preg_match('/^\x00\x00\x01\x00/', $data)) $type = 'ico'; 
     501//  else if (preg_match('/^\xFF\xD8\xFF\xE0/', $data)) $type = 'jpeg'; 
     502 
     503    return 'image/' . $type; 
     504} 
     505 
     506 
    488507/** 
    489508 * A method to guess encoding of a string. 
  • branches/devel-addressbook/program/steps/addressbook/show.inc

    r4317 r4324  
    4343    } 
    4444     
    45     // check some magic numbers to detect image type 
    46     $type = 'jpeg'; 
    47     if (preg_match('/^\x89\x50\x4E\x47/', $data))      $type = 'png'; 
    48     else if (preg_match('/^\x47\x49\x46\x38/', $data)) $type = 'gif'; 
    49     else if (preg_match('/^\x00\x00\x01\x00/', $data)) $type = 'ico'; 
    50 //  else if (preg_match('/^\xFF\xD8\xFF\xE0/', $data)) $type = 'jpeg'; 
    51      
    52     header('Content-Type: image/' . $type); 
     45    header('Content-Type: ' . rc_image_content_type($data)); 
    5346    echo $data ? $data : file_get_contents('program/blank.gif'); 
    5447    exit; 
Note: See TracChangeset for help on using the changeset viewer.