Advertisement
krot

IPTC data manipulator for JPEG images

Dec 16th, 2016
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.98 KB | None | 0 0
  1.  
  2.  
  3.  
  4.     /************************************************************\
  5.    
  6.         IPTC EASY 1.0 - IPTC data manipulator for JPEG images
  7.            
  8.         All reserved www.image-host-script.com
  9.        
  10.         Sep 15, 2008
  11.    
  12.     \************************************************************/
  13.  
  14.     DEFINE('IPTC_OBJECT_NAME', '005');
  15.     DEFINE('IPTC_EDIT_STATUS', '007');
  16.     DEFINE('IPTC_PRIORITY', '010');
  17.     DEFINE('IPTC_CATEGORY', '015');
  18.     DEFINE('IPTC_SUPPLEMENTAL_CATEGORY', '020');
  19.     DEFINE('IPTC_FIXTURE_IDENTIFIER', '022');
  20.     DEFINE('IPTC_KEYWORDS', '025');
  21.     DEFINE('IPTC_RELEASE_DATE', '030');
  22.     DEFINE('IPTC_RELEASE_TIME', '035');
  23.     DEFINE('IPTC_SPECIAL_INSTRUCTIONS', '040');
  24.     DEFINE('IPTC_REFERENCE_SERVICE', '045');
  25.     DEFINE('IPTC_REFERENCE_DATE', '047');
  26.     DEFINE('IPTC_REFERENCE_NUMBER', '050');
  27.     DEFINE('IPTC_CREATED_DATE', '055');
  28.     DEFINE('IPTC_CREATED_TIME', '060');
  29.     DEFINE('IPTC_ORIGINATING_PROGRAM', '065');
  30.     DEFINE('IPTC_PROGRAM_VERSION', '070');
  31.     DEFINE('IPTC_OBJECT_CYCLE', '075');
  32.     DEFINE('IPTC_BYLINE', '080');
  33.     DEFINE('IPTC_BYLINE_TITLE', '085');
  34.     DEFINE('IPTC_CITY', '090');
  35.     DEFINE('IPTC_PROVINCE_STATE', '095');
  36.     DEFINE('IPTC_COUNTRY_CODE', '100');
  37.     DEFINE('IPTC_COUNTRY', '101');
  38.     DEFINE('IPTC_ORIGINAL_TRANSMISSION_REFERENCE',     '103');
  39.     DEFINE('IPTC_HEADLINE', '105');
  40.     DEFINE('IPTC_CREDIT', '110');
  41.     DEFINE('IPTC_SOURCE', '115');
  42.     DEFINE('IPTC_COPYRIGHT_STRING', '116');
  43.     DEFINE('IPTC_CAPTION', '120');
  44.     DEFINE('IPTC_LOCAL_CAPTION', '121');
  45.  
  46.     class iptc {
  47.         var $meta=Array();
  48.         var $hasmeta=false;
  49.         var $file=false;
  50.        
  51.        
  52.         function iptc($filename) {
  53.             $size = getimagesize($filename,$info);
  54.             $this->hasmeta = isset($info["APP13"]);
  55.             if($this->hasmeta)
  56.                 $this->meta = iptcparse ($info["APP13"]);
  57.             $this->file = $filename;
  58.         }
  59.         function set($tag, $data) {
  60.             $this->meta ["2#$tag"]= Array( $data );
  61.             $this->hasmeta=true;
  62.         }
  63.         function get($tag) {
  64.             return isset($this->meta["2#$tag"]) ? $this->meta["2#$tag"][0] : false;
  65.         }
  66.        
  67.         function dump() {
  68.             print_r($this->meta);
  69.         }
  70.         function binary() {
  71.             $iptc_new = '';
  72.             foreach (array_keys($this->meta) as $s) {
  73.                 $tag = str_replace("2#", "", $s);
  74.                 $iptc_new .= $this->iptc_maketag(2, $tag, $this->meta[$s][0]);
  75.             }      
  76.             return $iptc_new;  
  77.         }
  78.         function iptc_maketag($rec,$dat,$val) {
  79.             $len = strlen($val);
  80.             if ($len < 0x8000) {
  81.                    return chr(0x1c).chr($rec).chr($dat).
  82.                    chr($len >> 8).
  83.                    chr($len & 0xff).
  84.                    $val;
  85.             } else {
  86.                    return chr(0x1c).chr($rec).chr($dat).
  87.                    chr(0x80).chr(0x04).
  88.                    chr(($len >> 24) & 0xff).
  89.                    chr(($len >> 16) & 0xff).
  90.                    chr(($len >> 8 ) & 0xff).
  91.                    chr(($len ) & 0xff).
  92.                    $val;
  93.                  
  94.             }
  95.         }  
  96.         function write() {
  97.             if(!function_exists('iptcembed')) return false;
  98.             $mode = 0;
  99.             $content = iptcembed($this->binary(), $this->file, $mode);  
  100.             $filename = $this->file;
  101.                
  102.             @unlink($filename); #delete if exists
  103.          
  104.             $fp = fopen($filename, "w");
  105.             fwrite($fp, $content);
  106.             fclose($fp);
  107.         }  
  108.        
  109.         #requires GD library installed
  110.        function removeAllTags() {
  111.             $this->hasmeta=false;
  112.             $this->meta=Array();
  113.             $img = imagecreatefromstring(implode(file($this->file)));
  114.             @unlink($this->file); #delete if exists
  115.            imagejpeg($img,$this->file,100);
  116.         }
  117.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement