예제 #1
2
function getexif($img)
{
    $imgtype = array("", "GIF", "JPG", "PNG", "SWF", "PSD", "BMP", "TIFF(intel byte order)", "TIFF(motorola byte order)", "JPC", "JP2", "JPX", "JB2", "SWC", "IFF", "WBMP", "XBM");
    $Orientation = array("", "top left side", "top right side", "bottom right side", "bottom left side", "left side top", "right side top", "right side bottom", "left side bottom");
    $ResolutionUnit = exif_lang('resolutionunit');
    $YCbCrPositioning = array("", "the center of pixel array", "the datum point");
    $ExposureProgram = exif_lang('exposureprogram');
    $MeteringMode_arr = exif_lang('meteringmode');
    $Lightsource_arr = exif_lang('lightsource');
    $Flash_arr = array("0" => "flash did not fire", "1" => "flash fired", "5" => "flash fired but strobe return light not detected", "7" => "flash fired and strobe return light detected");
    if (!function_exists('exif_read_data')) {
        return exif_lang('img_info');
    }
    $exif = @exif_read_data($img, "IFD0");
    if ($exif === false) {
        $new_img_info = exif_lang('img_info');
    } else {
        @($exif = exif_read_data($img, 0, true));
        foreach ($exif as $type => $typearr) {
            foreach ($typearr as $key => $kval) {
                if (is_array($kval)) {
                    foreach ($kval as $vkey => $value) {
                        $str = dhtmlspecialchars(preg_replace("/[^\\[A-Za-z0-9_\\.\\/:\\s-\\]]/", '', trim($value)));
                        $exif[$type][$key][$vkey] = $str;
                    }
                } elseif (!in_array($key, array('ComponentsConfiguration', 'FileSource', 'SceneType'))) {
                    $str = dhtmlspecialchars(preg_replace("/[^\\[A-Za-z0-9_\\.\\/:\\s-\\]]/", '', trim($kval)));
                    $exif[$type][$key] = $str;
                }
            }
        }
        $new_img_info = array(exif_lang('FileName') => $exif[FILE][FileName], exif_lang('FileType') => $imgtype[$exif[FILE][FileType]], exif_lang('MimeType') => $exif[FILE][MimeType], exif_lang('FileSize') => $exif[FILE][FileSize], exif_lang('FileDateTime') => date("Y-m-d H:i:s", $exif[FILE][FileDateTime]), exif_lang('ImageDescription') => $exif[IFD0][ImageDescription], exif_lang('Make') => $exif[IFD0][Make], exif_lang('Model') => $exif[IFD0][Model], exif_lang('Orientation') => $Orientation[$exif[IFD0][Orientation]], exif_lang('XResolution') => $exif[IFD0][XResolution] . $ResolutionUnit[$exif[IFD0][ResolutionUnit]], exif_lang('YResolution') => $exif[IFD0][YResolution] . $ResolutionUnit[$exif[IFD0][ResolutionUnit]], exif_lang('Software') => $exif[IFD0][Software], exif_lang('DateTime') => $exif[IFD0][DateTime], exif_lang('Artist') => $exif[IFD0][Artist], exif_lang('YCbCrPositioning') => $YCbCrPositioning[$exif[IFD0][YCbCrPositioning]], exif_lang('Copyright') => $exif[IFD0][Copyright], exif_lang('Photographer') => $exif[COMPUTED][Copyright . Photographer], exif_lang('Editor') => $exif[COMPUTED][Copyright . Editor], exif_lang('ExifVersion') => $exif[EXIF][ExifVersion], exif_lang('FlashPixVersion') => "Ver. " . number_format($exif[EXIF][FlashPixVersion] / 100, 2), exif_lang('DateTimeOriginal') => $exif[EXIF][DateTimeOriginal], exif_lang('DateTimeDigitized') => $exif[EXIF][DateTimeDigitized], exif_lang('Height') => $exif[COMPUTED][Height], exif_lang('Width') => $exif[COMPUTED][Width], exif_lang('ApertureValue') => $exif[EXIF][ApertureValue], exif_lang('ShutterSpeedValue') => $exif[EXIF][ShutterSpeedValue], exif_lang('ApertureFNumber') => $exif[COMPUTED][ApertureFNumber], exif_lang('MaxApertureValue') => "F" . $exif[EXIF][MaxApertureValue], exif_lang('ExposureTime') => $exif[EXIF][ExposureTime], exif_lang('FNumber') => $exif[EXIF][FNumber], exif_lang('MeteringMode') => getimageinfoval($exif[EXIF][MeteringMode], $MeteringMode_arr), exif_lang('LightSource') => getimageinfoval($exif[EXIF][LightSource], $Lightsource_arr), exif_lang('Flash') => getimageinfoval($exif[EXIF][Flash], $Flash_arr), exif_lang('ExposureMode') => $exif[EXIF][ExposureMode] == 1 ? exif_lang('manual') : exif_lang('auto'), exif_lang('WhiteBalance') => $exif[EXIF][WhiteBalance] == 1 ? exif_lang('manual') : exif_lang('auto'), exif_lang('ExposureProgram') => $ExposureProgram[$exif[EXIF][ExposureProgram]], exif_lang('ExposureBiasValue') => $exif[EXIF][ExposureBiasValue] . "EV", exif_lang('ISOSpeedRatings') => $exif[EXIF][ISOSpeedRatings], exif_lang('ComponentsConfiguration') => bin2hex($exif[EXIF][ComponentsConfiguration]) == "01020300" ? "YCbCr" : "RGB", exif_lang('CompressedBitsPerPixel') => $exif[EXIF][CompressedBitsPerPixel] . "Bits/Pixel", exif_lang('FocusDistance') => $exif[COMPUTED][FocusDistance] . "m", exif_lang('FocalLength') => $exif[EXIF][FocalLength] . "mm", exif_lang('FocalLengthIn35mmFilm') => $exif[EXIF][FocalLengthIn35mmFilm] . "mm", exif_lang('UserCommentEncoding') => $exif[COMPUTED][UserCommentEncoding], exif_lang('UserComment') => $exif[COMPUTED][UserComment], exif_lang('ColorSpace') => $exif[EXIF][ColorSpace] == 1 ? "sRGB" : "Uncalibrated", exif_lang('ExifImageLength') => $exif[EXIF][ExifImageLength], exif_lang('ExifImageWidth') => $exif[EXIF][ExifImageWidth], exif_lang('FileSource') => bin2hex($exif[EXIF][FileSource]) == 0x3 ? "digital still camera" : "unknown", exif_lang('SceneType') => bin2hex($exif[EXIF][SceneType]) == 0x1 ? "A directly photographed image" : "unknown", exif_lang('ThumbFileType') => $exif[COMPUTED][Thumbnail . FileType], exif_lang('ThumbMimeType') => $exif[COMPUTED][Thumbnail . MimeType]);
    }
    return $new_img_info;
}
예제 #2
1
 private function getImage()
 {
     $image = imagecreatefromstring(file_get_contents($this->file['tmp_name']));
     if ($this->currentExtension == 'jpg' || $this->currentExtension == 'jpeg') {
         $exif = exif_read_data($this->file['tmp_name']);
         if (!empty($exif['Orientation'])) {
             switch ($exif['Orientation']) {
                 case 8:
                     $image = imagerotate($image, 90, 0);
                     break;
                 case 3:
                     $image = imagerotate($image, 180, 0);
                     break;
                 case 6:
                     $image = imagerotate($image, -90, 0);
                     break;
             }
         }
     }
     // Get new sizes
     $width = imagesx($image);
     $height = imagesy($image);
     //list($width, $height) = getimagesize($this->file['tmp_name']);
     list($newWidth, $newHeight) = $this->getScaledDimArray($image, 800);
     // Load
     $resizeImage = imagecreatetruecolor($newWidth, $newHeight);
     // Resize
     imagecopyresized($resizeImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
     return $resizeImage;
 }
예제 #3
1
파일: exif.class.php 프로젝트: vluo/myPoto
 function get_exif($file)
 {
     if (!function_exists('exif_read_data')) {
         return false;
     }
     $exif = @exif_read_data($file, "IFD0");
     if ($exif === false) {
         return false;
     }
     $exif_info = exif_read_data($file, NULL, true);
     $exif_arr = $this->supported_exif();
     $new_exif = array();
     foreach ($exif_arr as $k => $v) {
         $arr = explode('.', $v);
         if (isset($exif_info[$arr[0]])) {
             if (isset($exif_info[$arr[0]][$arr[1]])) {
                 $new_exif[$k] = $exif_info[$arr[0]][$arr[1]];
             } else {
                 $new_exif[$k] = false;
             }
         } else {
             $new_exif[$k] = false;
         }
         if ($k == 'Software' && !empty($new_exif['Software'])) {
             $new_exif['Software'] = preg_replace('/([^a-zA-Z0-9_\\-,\\.\\:&#@!\\(\\)\\s]+)/i', '', $new_exif['Software']);
         }
     }
     return $new_exif;
 }
예제 #4
0
/**
 * This function extracts the EXIF data from a JPG image and convert then convert the GPS coordinates in degree
 *
 * @param $img
 * @param $directory
 *
 */
function readJPGExifData($img, $directory)
{
    $imgDir = $directory . $img;
    //reading exif data
    $exif = exif_read_data($imgDir, 0, true);
    //preparing the GPS coordinates
    $gpsLat = $exif["GPS"]["GPSLatitude"];
    $degLat = $gpsLat[0];
    $minLat = $gpsLat[1];
    $secLat = $gpsLat[2];
    $gpsLng = $exif["GPS"]["GPSLongitude"];
    $degLon = $gpsLng[0];
    $minLon = $gpsLng[1];
    $secLon = $gpsLng[2];
    //converting GPS lat data to degree
    $secLat = $secLat[0] . $secLat[1] . "," . $secLat[2] . $secLat[3] . $secLat[4];
    $minLat2 = $minLat / 60;
    $secLat2 = $secLat * (1 / 3600);
    $lat = $degLat + $minLat2 + $secLat2;
    //Lat coordinate - degree
    //converting GPS long data to degree
    $secLon = $secLon[0] . $secLon[1] . "," . $secLon[2] . $secLon[3] . $secLon[4];
    $minLon2 = $minLon / 60;
    $secLon2 = $secLon * (1 / 3600);
    $lng = $degLon + $minLon2 + $secLon2;
    //Long coordinate - degree
    //creating Drupal content with the image lat, lng data
    createContentFromImage($lat, $lng, $img);
    //removing the image to prevent any kind of confusion next time
    @unlink($_SERVER["DOCUMENT_ROOT"] . $imgDir);
}
예제 #5
0
 /**
  * Create Exif class
  *
  * @param string $file 
  * @author Thibaud Rohmer
  */
 public function __construct($file = null)
 {
     /// No file given
     if (!isset($file)) {
         return;
     }
     /// File isn't an image
     if (is_array($file) || !File::Type($file) || File::Type($file) != "Image") {
         return;
     }
     /// No right to view
     if (!Judge::view($file)) {
         return;
     }
     /// No exif extension installed
     if (!in_array("exif", get_loaded_extensions())) {
         $infos[''] = "Exif extension is not installed on the server";
         return;
     }
     /// Create wanted table
     $this->init_wanted();
     /// Read exif
     $raw_exif = @exif_read_data($file);
     /// Parse exif
     foreach ($this->wanted as $name => $data) {
         foreach ($data as $d) {
             if (isset($raw_exif[$d])) {
                 $this->exif[$name] = $this->parse_exif($d, $raw_exif);
             }
         }
     }
     $this->filename = basename($file);
 }
예제 #6
0
 /**
  * Get image orientation from exif
  */
 public static function get_orientation_degrees($filename)
 {
     if (in_array("exif", get_loaded_extensions())) {
         $raw_exif = @exif_read_data($filename);
         switch ($raw_exif['Orientation']) {
             case 1:
             case 2:
                 $degrees = 0;
                 break;
             case 3:
             case 4:
                 $degrees = 180;
                 break;
             case 5:
             case 6:
                 $degrees = -90;
                 break;
             case 7:
             case 8:
                 $degrees = 90;
                 break;
             default:
                 $degrees = 0;
         }
     } else {
         $degrees = 0;
     }
     return $degrees;
 }
예제 #7
0
 public function set($k, $v)
 {
     switch ($k) {
         case 'file':
             $ret = parent::set($k, $v);
             // Clear out the cache
             $this->_file = null;
             // File was updated... load the exif data too!
             // Note, only do this if it was an image!
             $file = $this->getOriginalFile();
             if ($file->isImage() && $file->getExtension() == 'jpg') {
                 $this->_data['exifdata'] = json_encode(exif_read_data($file->getFilename()));
             } else {
                 $this->_data['exifdata'] = null;
             }
             // Also if the file is new and it didn't exist... set the uploader id.
             if (!$this->_exists) {
                 $this->_data['uploaderid'] = \Core\user()->get('id');
             }
             return $ret;
         case 'exifdata':
             // exif data cannot be changed externally!
             return false;
         default:
             return parent::set($k, $v);
     }
 }
 /**
  * Class constructor
  * 
  * @param int $image Image ID
  * @param bool $onlyEXIF TRUE = will parse only EXIF data
  * @return bool FALSE if the file does not exist or metadat could not be read
  */
 public function __construct($image, $onlyEXIF = FALSE)
 {
     if (is_numeric($image)) {
         $image = $this->get_registry()->get_utility('I_Image_Mapper')->find($image);
     }
     $this->image = apply_filters('ngg_find_image_meta', $image);
     $this->file_path = $this->get_registry()->get_utility('I_Gallery_Storage')->get_image_abspath($this->image);
     if (!@file_exists($this->file_path)) {
         return FALSE;
     }
     $this->size = @getimagesize($this->file_path, $metadata);
     if ($this->size && is_array($metadata)) {
         // get exif - data
         if (is_callable('exif_read_data')) {
             $this->exif_data = @exif_read_data($this->file_path, 0, TRUE);
         }
         // stop here if we didn't need other meta data
         if ($onlyEXIF) {
             return TRUE;
         }
         // get the iptc data - should be in APP13
         if (is_callable('iptcparse') && isset($metadata['APP13'])) {
             $this->iptc_data = @iptcparse($metadata['APP13']);
         }
         // get the xmp data in a XML format
         if (is_callable('xml_parser_create')) {
             $this->xmp_data = $this->extract_XMP($this->file_path);
         }
         return TRUE;
     }
     return FALSE;
 }
예제 #9
0
 function getid3_jpg(&$fd, &$ThisFileInfo)
 {
     $ThisFileInfo['fileformat'] = 'jpg';
     $ThisFileInfo['video']['dataformat'] = 'jpg';
     $ThisFileInfo['video']['lossless'] = false;
     $ThisFileInfo['video']['bits_per_sample'] = 24;
     $ThisFileInfo['video']['pixel_aspect_ratio'] = (double) 1;
     fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
     list($width, $height, $type) = getid3_lib::GetDataImageSize(fread($fd, $ThisFileInfo['filesize']));
     if ($type == 2) {
         $ThisFileInfo['video']['resolution_x'] = $width;
         $ThisFileInfo['video']['resolution_y'] = $height;
         if (version_compare(phpversion(), '4.2.0', '>=')) {
             if (function_exists('exif_read_data')) {
                 ob_start();
                 $ThisFileInfo['jpg']['exif'] = exif_read_data($ThisFileInfo['filenamepath'], '', true, false);
                 $errors = ob_get_contents();
                 if ($errors) {
                     $ThisFileInfo['error'][] = strip_tags($errors);
                     unset($ThisFileInfo['jpg']['exif']);
                 }
                 ob_end_clean();
             } else {
                 $ThisFileInfo['warning'][] = 'EXIF parsing only available when ' . (GETID3_OS_ISWINDOWS ? 'php_exif.dll enabled' : 'compiled with --enable-exif');
             }
         } else {
             $ThisFileInfo['warning'][] = 'EXIF parsing only available in PHP v4.2.0 and higher compiled with --enable-exif (or php_exif.dll enabled for Windows). You are using PHP v' . phpversion();
         }
         return true;
     }
     unset($ThisFileInfo['fileformat']);
     return false;
 }
예제 #10
0
 public function display_image(Page $page, Image $image)
 {
     global $config;
     $u_ilink = $image->get_image_link();
     if ($config->get_bool("image_show_meta") && function_exists("exif_read_data")) {
         # FIXME: only read from jpegs?
         $exif = @exif_read_data($image->get_image_filename(), 0, true);
         if ($exif) {
             $head = "";
             foreach ($exif as $key => $section) {
                 foreach ($section as $name => $val) {
                     if ($key == "IFD0") {
                         // Cheap fix for array'd values in EXIF-data
                         if (is_array($val)) {
                             $val = implode(',', $val);
                         }
                         $head .= html_escape("{$name}: {$val}") . "<br>\n";
                     }
                 }
             }
             if ($head) {
                 $page->add_block(new Block("EXIF Info", $head, "left"));
             }
         }
     }
     $html = "<img alt='main image' class='shm-main-image' id='main_image' src='{$u_ilink}' " . "data-width='{$image->width}' data-height='{$image->height}'>";
     $page->add_block(new Block("Image", $html, "main", 10));
 }
예제 #11
0
 function save($filename, $image_type = 2, $compression = 80, $permissions = null)
 {
     if ($image_type == 2) {
         //jpg
         $exif = exif_read_data($filename);
         $ort = 1;
         if (isset($exif['Orientation'])) {
             $ort = $exif['Orientation'];
         }
         if ($ort == 3) {
             $this->image = imagerotate($this->image, 180, -1);
         } else {
             if ($ort == 5 || $ort == 6 || $ort == 7) {
                 $this->image = imagerotate($this->image, -90, -1);
             } else {
                 if ($ort == 8) {
                     $this->image = imagerotate($this->image, 90, -1);
                 }
             }
         }
         imagejpeg($this->image, $filename);
         //imagejpeg($this->image,$filename,$compression);
     } elseif ($image_type == 1) {
         //gif
         imagegif($this->image, $filename);
     } elseif ($image_type == 3) {
         //png
         imagepng($this->image, $filename);
     }
     if ($permissions != null) {
         chmod($filename, $permissions);
     }
 }
예제 #12
0
 public function add($fileName, $description = null, $date = null)
 {
     // create item
     $item["file"] = $fileName;
     $item["description"] = $description;
     if (!$date) {
         $exif_data = @exif_read_data($this->dir . "/" . $fileName);
         if ($exif_data !== false) {
             if (isset($exif_data['DateTimeOriginal'])) {
                 $date = $exif_data['DateTimeOriginal'];
             }
             if (empty($date) && isset($exif_data['DateTime'])) {
                 $date = $exif_data['DateTime'];
             }
             $this->logger->debug("exif date of " . $fileName . " : " . $date);
         }
     }
     $item["date"] = $date == null ? date("Y-M-d H:i:s") : $date;
     // resize in 4 sizes
     $this->samplePicture($fileName);
     // compute ratio
     $image_info = getimagesize(sprintf('%s/%s', $this->dir, $fileName));
     $item["ratio"] = $image_info[0] / $image_info[1];
     $item["reverseRatio"] = 1 / $item["ratio"];
     return $this->insert($item);
 }
예제 #13
0
 public function file()
 {
     $fileID = array_keys($_GET);
     $fileID = str_replace('files/', '', $fileID[0]);
     $fileInfo = $this->_files->getFileInfo($fileID);
     if (empty($fileInfo)) {
         header("{$_SERVER['SERVER_PROTOCOL']} 404 Not Found");
         $data['title'] = '404';
         $data['error'] = "Страница не найдена.";
         View::render('Error/404');
         die;
     }
     $data['title'] = $fileInfo['file_name'];
     $data['fileinfo'] = $fileInfo;
     if ($data['fileinfo']['file_type'] == 'image/jpg' || $data['fileinfo']['file_type'] == 'image/gif' || $data['fileinfo']['file_type'] == 'image/png') {
         $data['imageinfo'] = getimagesize($_SERVER['DOCUMENT_ROOT'] . '/uploads/' . $data['fileinfo']['server_name']);
     }
     if ($data['fileinfo']['file_type'] == 'image/jpg' || $data['fileinfo']['file_type'] == 'image/tiff') {
         $data['imageinfo']['saved'] = exif_read_data($_SERVER['DOCUMENT_ROOT'] . '/uploads/' . $data['fileinfo']['server_name']);
     }
     $fileType = array_shift(explode('/', $data['fileinfo']['file_type']));
     if ($fileType == 'video' || $fileType == 'audio') {
         $getID3 = new GetId3();
         $data['mediainfo'] = $getID3->setEncoding('UTF-8')->analyze($_SERVER['DOCUMENT_ROOT'] . '/uploads/' . $data['fileinfo']['server_name']);
     }
     $data['comments'] = $this->_files->getAllComments($fileID);
     $data['token'] = $this->makeToken();
     View::renderTemplate('header', $data);
     View::render('files/file', $data);
     View::renderTemplate('footer', $data);
 }
function flickr_photos_exif_read(&$photo)
{
    $map = flickr_photos_media_map();
    if ($map[$photo['media']] == 'video') {
        return not_okay("video does not contain EXIF data");
    }
    $fname = "{$photo['id']}_{$photo['originalsecret']}_o.{$photo['originalformat']}";
    $froot = $GLOBALS['cfg']['flickr_static_path'] . flickr_photos_id_to_path($photo['id']);
    $path = "{$froot}/{$fname}";
    if (!preg_match("/\\.jpe?g\$/i", $path)) {
        return not_okay("not a JPEG photo");
    }
    if (!file_exists($path)) {
        return not_okay("original photo not found");
    }
    if (!filesize($path)) {
        return not_okay("original photo is empty");
    }
    # TO DO: cache me?
    $exif = exif_read_data($path);
    if (!$exif) {
        return not_okay("failed to read EXIF data");
    }
    # TO DO: expand EXIF tag values
    $to_simplejoin = array('SubjectLocation', 'GPSLatitude', 'GPSLongitude', 'GPSTimeStamp');
    foreach ($to_simplejoin as $tag) {
        if (is_array($exif[$tag])) {
            $exif[$tag] = implode(",", $exif[$tag]);
        }
    }
    # TO DO: work out how/where individual EXIF tags get
    # "prettified" ...
    ksort($exif);
    return okay(array("rows" => $exif));
}
예제 #15
0
파일: image.php 프로젝트: jvinet/pronto
 /**
  * Automatically rotate an image based on EXIF data.  If the
  * IFD0[Orientation] header is available, this function will use
  * it to rotate the image to the correct orientation.
  *
  * @param string $srcType MIME type of the source file
  * @param string $srcFile Source filename
  * @param string $dstFile Destination filename, can be the same as $srcFile
  */
 function auto_rotate($srcType, $srcFile, $dstFile, $angle)
 {
     if (!extension_loaded('exif')) {
         trigger_error("ppImage::auto_rotate() requires the exif PHP extension.");
         return false;
     }
     $exif = exif_read_data($srcFile);
     if ($exif == false) {
         return false;
     }
     if (!isset($exif['IFD0']['Orientation'])) {
         return false;
     }
     $rotate = 0;
     $flip = false;
     switch ($o) {
         case 1:
             $rotate = 0;
             $flip = false;
             break;
         case 2:
             $rotate = 0;
             $flip = true;
             break;
         case 3:
             $rotate = 180;
             $flip = false;
             break;
         case 4:
             $rotate = 180;
             $flip = true;
             break;
         case 5:
             $rotate = 90;
             $flip = true;
             break;
         case 6:
             $rotate = 90;
             $flip = false;
             break;
         case 7:
             $rotate = 270;
             $flip = true;
             break;
         case 8:
             $rotate = 270;
             $flip = false;
             break;
     }
     if ($flip) {
         $this->flip($srcType, $srcFile, $srcFile, IMAGE_FLIP_HORIZONTAL);
     }
     if ($rotate) {
         $this->rotate($srcType, $srcFile, $srcFile, $rotate);
     }
     if ($srcFile != $dstFile) {
         copy($srcFile, $dstFile);
     }
     return true;
 }
 public function parseIPTC()
 {
     $aArr = @exif_read_data($this->sFilename, 'IDF0', true);
     $size = getimagesize($this->sFilename, $info);
     if (!isset($info['APP13'])) {
         return false;
     }
     $iptc = iptcparse($info['APP13']);
     if (isset($iptc["2#120"][0])) {
         # caption
         $this->aAttributes['title'] = trim($iptc["2#120"][0]);
     } else {
         if (isset($iptc["2#105"][0])) {
             # headline
             $this->aAttributes['title'] = trim($iptc["2#105"][0]);
         } else {
             if (isset($iptc["2#005"][0])) {
                 # graphic name
                 $this->aAttributes['title'] = trim($iptc["2#005"][0]);
             }
         }
     }
     if (isset($iptc["2#055"][0]) && isset($iptc["2#060"][0])) {
         # creation date
         $iTimestamp = self::timestampFromIPTC($iptc["2#055"][0], $iptc["2#060"][0]);
         if ($iTimestamp !== false) {
             $this->aAttributes['datetime'] = $iTimestamp;
         }
     }
     return true;
 }
예제 #17
0
 /**
  * nggMeta::nggMeta()
  * 
  * @param int $image path to a image
  * @param bool $onlyEXIF parse only exif if needed
  * @return
  */
 function nggMeta($pic_id, $onlyEXIF = false)
 {
     //get the path and other data about the image
     $this->image = nggdb::find_image($pic_id);
     $this->image = apply_filters('ngg_find_image_meta', $this->image);
     if (!file_exists($this->image->imagePath)) {
         return false;
     }
     $this->size = @getimagesize($this->image->imagePath, $metadata);
     if ($this->size && is_array($metadata)) {
         // get exif - data
         if (is_callable('exif_read_data')) {
             $this->exif_data = @exif_read_data($this->image->imagePath, 0, true);
         }
         // stop here if we didn't need other meta data
         if ($onlyEXIF) {
             return true;
         }
         // get the iptc data - should be in APP13
         if (is_callable('iptcparse') && isset($metadata['APP13'])) {
             $this->iptc_data = @iptcparse($metadata['APP13']);
         }
         // get the xmp data in a XML format
         if (is_callable('xml_parser_create')) {
             $this->xmp_data = $this->extract_XMP($this->image->imagePath);
         }
         return true;
     }
     return false;
 }
예제 #18
0
 function fix($path)
 {
     $image = imagecreatefromjpeg($path);
     $exif = exif_read_data($path);
     if (!empty($exif['Orientation'])) {
         switch ($exif['Orientation']) {
             case 1:
                 break;
             case 2:
                 imageflip($image, IMG_FLIP_HORIZONTAL);
                 break;
             case 3:
                 $image = imagerotate($image, 180, 0);
                 break;
             case 4:
                 imageflip($image, IMG_FLIP_VERTICAL);
                 break;
             case 5:
                 $image = imagerotate($image, 90, 0);
                 imageflip($image, IMG_FLIP_HORIZONTAL);
                 break;
             case 6:
                 $image = imagerotate($image, -90, 0);
                 break;
             case 7:
                 $image = imagerotate($image, -90, 0);
                 imageflip($image, IMG_FLIP_HORIZONTAL);
                 break;
             case 8:
                 $image = imagerotate($image, 90, 0);
                 break;
         }
         imagejpeg($image, $path);
     }
 }
예제 #19
0
 function fixImageOrientation($path)
 {
     $info = getimagesize($path);
     if ($info['mime'] != "image/jpeg") {
         return;
     }
     $exif = exif_read_data($path);
     if (exif_imagetype($path) != IMAGETYPE_JPEG) {
         return;
     }
     if (empty($exif['Orientation'])) {
         return;
     }
     $image = imagecreatefromjpeg($path);
     switch ($exif['Orientation']) {
         case 3:
             $image = imagerotate($image, 180, 0);
             break;
         case 6:
             $image = imagerotate($image, -90, 0);
             break;
         case 8:
             $image = imagerotate($image, 90, 0);
             break;
     }
     imagejpeg($image, $path);
 }
예제 #20
0
 function process($mimeData, $parameters = array())
 {
     $printInfo = false;
     if (isset($parameters['print_info'])) {
         $printInfo = $parameters['print_info'];
     }
     $filename = $mimeData['url'];
     if (file_exists($filename)) {
         if (function_exists('exif_read_data')) {
             $exifData = exif_read_data($filename, "COMPUTED,IFD0,COMMENT,EXIF", true);
             if ($exifData) {
                 $info = array();
                 if (isset($exifData['COMPUTED'])) {
                     foreach ($exifData['COMPUTED'] as $key => $item) {
                         if (strtolower($key) == 'html') {
                             continue;
                         }
                         $info[$key] = $exifData['COMPUTED'][$key];
                     }
                 }
                 if (isset($exifData['IFD0'])) {
                     $info['ifd0'] = $exifData['IFD0'];
                 }
                 if (isset($exifData['EXIF'])) {
                     $info['exif'] = $exifData['EXIF'];
                 }
                 return $info;
             }
         }
     }
     return false;
 }
예제 #21
0
 public function fixOrientation()
 {
     if (!in_array($this->type, ['image/jpeg', 'image/jpg', 'image/tiff', 'image/tiff'])) {
         return false;
     }
     $exif = exif_read_data($this->path);
     if (isset($exif['Orientation'])) {
         $orientation = $exif['Orientation'];
     } elseif (isset($exif['IFD0']['Orientation'])) {
         $orientation = $exif['IFD0']['Orientation'];
     } else {
         return false;
     }
     switch ($orientation) {
         case 3:
             // rotate 180 degrees
             $this->image->rotateImage('#FFF', 180);
             break;
         case 6:
             // rotate 90 degrees CW
             $this->image->rotateImage('#FFF', 90);
             break;
         case 8:
             // rotate 90 degrees CCW
             $this->image->rotateImage('#FFF', -90);
             break;
     }
 }
예제 #22
0
 /**
  * Read the Information from a picture according to the fields specified in CCK
  * @param $file
  * @param $arTagNames
  * @return array
  */
 public function readExifTags($file, $arTagNames = array())
 {
     if (!file_exists($file)) {
         return array();
     }
     $ar_supported_types = array('jpg', 'jpeg');
     if (!in_array(strtolower($this->getFileType($file)), $ar_supported_types)) {
         return array();
     }
     $exif = exif_read_data($file, 0);
     $arSmallExif = array();
     $arSmallExif = array_change_key_case((array) $exif, CASE_LOWER);
     $arSmallExif['computed'] = array_change_key_case((array) $arSmallExif['computed'], CASE_LOWER);
     //why this function isn't recursive is beyond me
     $arSmallExif['thumbnail'] = array_change_key_case((array) $arSmallExif['thumbnail'], CASE_LOWER);
     $arSmallExif['comment'] = array_change_key_case((array) $arSmallExif['comment'], CASE_LOWER);
     $info = array();
     foreach ($arTagNames as $tagName) {
         if ($tagName['section'] != 'iptc') {
             if (!empty($arSmallExif[$tagName['tag']])) {
                 $info[$tagName['section'] . '_' . $tagName['tag']] = $arSmallExif[$tagName['tag']];
             } elseif (!empty($arSmallExif[$tagName['section']][$tagName['tag']])) {
                 $info[$tagName['section'] . '_' . $tagName['tag']] = $arSmallExif[$tagName['section']][$tagName['tag']];
             }
         }
     }
     foreach ($info as $tag => $value) {
         if (!is_array($value)) {
             $info[$tag] = utf8_encode($value);
         }
     }
     return $info;
 }
예제 #23
0
 /**
  * nggMeta::nggMeta()
  * 
  * @param string $image path to a image
  * @param bool $onlyEXIF parse only exif if needed
  * @return
  */
 function nggMeta($image, $onlyEXIF = false)
 {
     $this->imagePath = $image;
     if (!file_exists($this->imagePath)) {
         return false;
     }
     $size = @getimagesize($this->imagePath, $metadata);
     if ($size && is_array($metadata)) {
         // get exif - data
         if (is_callable('exif_read_data')) {
             $this->exif_data = @exif_read_data($this->imagePath, 0, true);
         }
         // stop here if we didn't need other meta data
         if ($onlyEXIF) {
             return true;
         }
         // get the iptc data - should be in APP13
         if (is_callable('iptcparse')) {
             $this->iptc_data = @iptcparse($metadata["APP13"]);
         }
         // get the xmp data in a XML format
         if (is_callable('xml_parser_create')) {
             $this->xmp_data = $this->extract_XMP($this->imagePath);
         }
         return true;
     }
     return false;
 }
예제 #24
0
 /**
  * Load an image
  *
  * @param $filename
  * @return Image
  * @throws Exception
  */
 public static function load($filename)
 {
     $instance = new self();
     // Require GD library
     if (!extension_loaded('gd')) {
         throw new Exception('Required extension GD is not loaded.');
     }
     $instance->filename = $filename;
     $info = getimagesize($instance->filename);
     switch ($info['mime']) {
         case 'image/gif':
             $instance->image = imagecreatefromgif($instance->filename);
             break;
         case 'image/jpeg':
             $instance->image = imagecreatefromjpeg($instance->filename);
             break;
         case 'image/png':
             $instance->image = imagecreatefrompng($instance->filename);
             imagesavealpha($instance->image, true);
             imagealphablending($instance->image, true);
             break;
         default:
             throw new Exception('Invalid image: ' . $instance->filename);
             break;
     }
     $instance->original_info = array('width' => $info[0], 'height' => $info[1], 'orientation' => $instance->get_orientation(), 'exif' => function_exists('exif_read_data') ? $instance->exif = @exif_read_data($instance->filename) : null, 'format' => preg_replace('/^image\\//', '', $info['mime']), 'mime' => $info['mime']);
     $instance->width = $info[0];
     $instance->height = $info[1];
     imagesavealpha($instance->image, true);
     imagealphablending($instance->image, true);
     return $instance;
 }
예제 #25
0
파일: app2.php 프로젝트: OmniPics/OmniPics
function getEXIF($path, $filename)
{
    $exif = exif_read_data($path . $filename);
    //print_r($exif);
    $array = array("FileDateTime" => $exif['FileDateTime'], "FileSize" => $exif['FileSize'], "FileType" => $exif['FileType'], "MimeType" => $exif['MimeType'], "ComputedWidth" => $exif['COMPUTED']['Width'], "ComputedHeight" => $exif['COMPUTED']['Height']);
    print_r($array);
}
예제 #26
0
파일: Photos.php 프로젝트: bersace/strass
 function storeFile($path)
 {
     $activite = $this->findParentActivites();
     /* date */
     $exif = @exif_read_data($path);
     if ($exif && array_key_exists('DateTimeOriginal', $exif)) {
         preg_match("`(\\d{4})[:-](\\d{2})[:-](\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})`", $exif['DateTimeOriginal'], $match);
         $this->date = $match[1] . '-' . $match[2] . '-' . $match[3] . ' ' . $match[4] . ':' . $match[5] . ':' . $match[6];
     } else {
         $this->date = $activite->fin;
     }
     $dossier = $activite->getDossierPhoto();
     if (!file_exists($dossier)) {
         mkdir($dossier, 0755, true);
     }
     $suffixe = '.jpeg';
     $vignette = $dossier . '/' . $this->slug . '-vignette' . $suffixe;
     $fichier = $dossier . '/' . $this->slug . $suffixe;
     $config = Zend_Registry::get('config');
     $photo = Strass_Vignette::charger($path, $fichier, true);
     $width = $photo->getWidth();
     $height = $photo->getHeight();
     $MAX = $config->get('photo/taille', 2048);
     if (min($width, $height) > $MAX) {
         $photo->scale($MAX, $MAX);
     }
     $photo->ecrire();
     Strass_Vignette::decouper($photo, $vignette);
     $this->save();
 }
예제 #27
0
function getJPGHeaderFilepointer(&$fd, &$ThisFileInfo)
{
    $ThisFileInfo['fileformat'] = 'jpg';
    $ThisFileInfo['video']['dataformat'] = 'jpg';
    $ThisFileInfo['video']['lossless'] = false;
    $ThisFileInfo['video']['bits_per_sample'] = 24;
    fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
    require_once GETID3_INCLUDEPATH . 'getid3.getimagesize.php';
    list($width, $height, $type) = GetDataImageSize(fread($fd, $ThisFileInfo['filesize']));
    if ($type == 2) {
        $ThisFileInfo['video']['resolution_x'] = $width;
        $ThisFileInfo['video']['resolution_y'] = $height;
        if (version_compare(phpversion(), '4.2.0', '>=')) {
            if (function_exists('exif_read_data')) {
                ob_start();
                $ThisFileInfo['jpg']['exif'] = exif_read_data($ThisFileInfo['filenamepath'], '', true, false);
                $errors = ob_get_contents();
                if ($errors) {
                    $ThisFileInfo['warning'] .= "\n" . strip_tags($errors);
                    unset($ThisFileInfo['jpg']['exif']);
                }
                ob_end_clean();
            } else {
                $ThisFileInfo['error'] .= "\n" . 'EXIF parsing only available when compiled with --enable-exif (or php_exif.dll enabled for Windows)';
            }
        } else {
            $ThisFileInfo['error'] .= "\n" . 'EXIF parsing only available in PHP v4.2.0 and higher (you are using PHP v' . phpversion() . ') compiled with --enable-exif (or php_exif.dll enabled for Windows)';
        }
        return true;
    }
    unset($ThisFileInfo['fileformat']);
    return false;
}
 /**
  * Gets the orientation of an image file.
  *
  * @param string $imageFile Image file to get the orientation from.
  * @return int The degree of orientation.
  */
 public static function getImageOrientation($imageFile)
 {
     if (!file_exists($imageFile)) {
         throw new \RuntimeException(sprintf('File %s not found!', $imageFile));
     }
     $exif = exif_read_data($imageFile);
     if ($exif === false) {
         return false;
     }
     $angle = 0;
     if (!empty($exif['Orientation'])) {
         switch ($exif['Orientation']) {
             case 0:
                 $angle = 0;
                 break;
             case 3:
                 $angle = 180;
                 break;
             case 6:
                 $angle = -90;
                 break;
             case 8:
                 $angle = 90;
                 break;
             default:
                 $angle = 0;
                 break;
         }
         return $angle;
     }
     return $angle;
 }
예제 #29
0
파일: image.php 프로젝트: Norvares/nemex
 public function __construct($path)
 {
     list($this->width, $this->height, $this->type) = @getImageSize($path);
     if ($this->type == IMAGETYPE_JPEG) {
         $this->image = imageCreateFromJPEG($path);
         $this->extension = 'jpg';
         if (function_exists('exif_read_data')) {
             $this->exif = exif_read_data($path);
         }
         $this->rotateToExifOrientation();
     } else {
         if ($this->type == IMAGETYPE_PNG) {
             $this->image = imageCreateFromPNG($path);
             $this->extension = 'png';
         } else {
             if ($this->type == IMAGETYPE_GIF) {
                 $this->image = imageCreateFromGIF($path);
                 $this->extension = 'gif';
             }
         }
     }
     if ($this->image) {
         $this->valid = true;
     }
 }
예제 #30
-1
파일: Meta.php 프로젝트: fnocke/dirList
 public static function getAsJson($file, $force = false)
 {
     $json = array();
     getimagesize($file, $info);
     if (isset($info["APP13"])) {
         $iptc = iptcparse($info["APP13"]);
         if (isset($iptc['2#120'])) {
             $caption = implode('|', $iptc['2#120']);
             // nb: '|' should never actually appear
             $caption = ensureUTF8($caption);
             // since could be 'local' encoding
             $caption = mysql_escape_string($caption);
             // safety. stackoverflow.com/q/1162491
             $json['caption'] = $caption;
         }
         if (isset($iptc['2#025'])) {
             $json['keywords'] = $iptc['2#025'];
         }
         // keep as array
         set_error_handler("ignoreAnyError", E_ALL);
         // TOTEST, currently no exif enabled on localhost
         if (function_exists('exif_read_data')) {
             $json['exif'] = exif_read_data($tmpfile, 0, false);
         }
         // fails on a very few files (corrupt EXIF)
         restore_error_handler();
     }
     Log::info("json for :" . $file);
     Log::info($json);
     return $json;
 }