Advertisement
fruffl

class write exif/iptc

Aug 8th, 2011
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.62 KB | None | 0 0
  1. <?PHP
  2.  
  3.     CLASS ILLI_Container_Api_Image_Iptc
  4.     {
  5.             const IPTC_OBJECT_NAME = 005;
  6.             const IPTC_EDIT_STATUS = 007;
  7.             const IPTC_PRIORITY = 010;
  8.             const IPTC_CATEGORY = 015;
  9.             const IPTC_SUPPLEMENTAL_CATEGORY = 020;
  10.             const IPTC_FIXTURE_IDENTIFIER = 022;
  11.             const IPTC_KEYWORDS = 025;
  12.             const IPTC_RELEASE_DATE = 030;
  13.             const IPTC_RELEASE_TIME = 035;
  14.             const IPTC_SPECIAL_INSTRUCTIONS = 040;
  15.             const IPTC_REFERENCE_SERVICE = 045;
  16.             const IPTC_REFERENCE_DATE = 047;
  17.             const IPTC_REFERENCE_NUMBER = 050;
  18.             const IPTC_CREATED_DATE = 055;
  19.             const IPTC_CREATED_TIME = 060;
  20.             const IPTC_ORIGINATING_PROGRAM = 065;
  21.             const IPTC_PROGRAM_VERSION = 070;
  22.             const IPTC_OBJECT_CYCLE = 075;
  23.             const IPTC_BYLINE = 080;
  24.             const IPTC_BYLINE_TITLE = 085;
  25.             const IPTC_CITY = 090;
  26.             const IPTC_PROVINCE_STATE = 095;
  27.             const IPTC_COUNTRY_CODE = 100;
  28.             const IPTC_COUNTRY = 101;
  29.             const IPTC_ORIGINAL_TRANSMISSION_REFERENCE = 103;
  30.             const IPTC_HEADLINE = 105;
  31.             const IPTC_CREDIT = 110;
  32.             const IPTC_SOURCE = 115;
  33.             const IPTC_COPYRIGHT_STRING = 116;
  34.             const IPTC_CAPTION = 120;
  35.             const IPTC_LOCAL_CAPTION = 121;
  36.            
  37.             const RECORD = 2;
  38.            
  39.             private $metatable = array
  40.             (
  41.                 'objectname' => self::IPTC_OBJECT_NAME,
  42.                 'editstatus' => self::IPTC_EDIT_STATUS,
  43.                 'priority' => self::IPTC_PRIORITY,
  44.                 'category' => self::IPTC_CATEGORY,
  45.                 'supplementalcategory' => self::IPTC_SUPPLEMENTAL_CATEGORY,
  46.                 'fixtureident' => self::IPTC_FIXTURE_IDENTIFIER,
  47.                 'keywords' => self::IPTC_KEYWORDS,
  48.                 'releasedate' => self::IPTC_RELEASE_DATE,
  49.                 'releasetime' => self::IPTC_RELEASE_TIME,
  50.                 'specialinstructions' => self::IPTC_SPECIAL_INSTRUCTIONS,
  51.                 'referenceservice' => self::IPTC_REFERENCE_SERVICE,
  52.                 'referencedate' => self::IPTC_REFERENCE_DATE,
  53.                 'referencenumber' => self::IPTC_REFERENCE_NUMBER,
  54.                 'createddate' => self::IPTC_CREATED_DATE,
  55.                 'createdtime' => self::IPTC_CREATED_TIME,
  56.                 'program' => self::IPTC_ORIGINATING_PROGRAM,
  57.                 'programversion' => self::IPTC_PROGRAM_VERSION,
  58.                 'objectcycle' => self::IPTC_OBJECT_CYCLE,
  59.                 'byline' => self::IPTC_BYLINE,
  60.                 'bylinetitle' => self::IPTC_BYLINE_TITLE,
  61.                 'city' => self::IPTC_CITY,
  62.                 'provincestate' => self::IPTC_PROVINCE_STATE,
  63.                 'countrycode' => self::IPTC_COUNTRY_CODE,
  64.                 'country' => self::IPTC_COUNTRY,
  65.                 'transmissionreference' => self::IPTC_ORIGINAL_TRANSMISSION_REFERENCE,
  66.                 'headline' => self::IPTC_HEADLINE,
  67.                 'credit' => self::IPTC_CREDIT,
  68.                 'source' => self::IPTC_SOURCE,
  69.                 'copyright' => self::IPTC_COPYRIGHT_STRING,
  70.                 'caption' => self::IPTC_CAPTION,
  71.                 'localcaption' => self::IPTC_LOCAL_CAPTION,
  72.             );
  73.            
  74.             private $path = NULL;
  75.             private $meta = array();
  76.             private $iptcmeta = '';
  77.            
  78.             public function __call($name, $value)
  79.             {
  80.                 if(substr($name, 0,4) !== 'set_')
  81.                     return $this;
  82.                
  83.                 $_name = strtolower(str_replace(substr($name, 0, 4), NULL, $name));
  84.                
  85.                 if(!array_key_exists($_name, $this->metatable))
  86.                     return $this;
  87.                    
  88.                 if(!isset($value[1]))
  89.                     $value[1] = self::RECORD;
  90.                    
  91.                 if(($value[1] = intval($value[1])) === 0)
  92.                     $value[1] = self::RECORD;
  93.                    
  94.                 $this->meta[$value[1].'#'.$this->metatable[$_name]] = $value[0];
  95.                
  96.                 return $this;
  97.             }
  98.            
  99.             public function save($path)
  100.             {
  101.                 if(FALSE === (bool) $this->meta)
  102.                     return $this;
  103.                
  104.                 if(!file_exists($path))
  105.                     return $this;
  106.                    
  107.                 $this->path = $path;
  108.                
  109.                 $this->iptcmeta = '';
  110.                 foreach($this->meta as $tag => $string)
  111.                     $this->iptcmeta .= $this->make_tag(substr($tag, 2), $string, substr($tag, 0, 1));
  112.                
  113.             $content = iptcembed($this->iptcmeta, $this->path);
  114.             file_put_contents($this->path, $content);
  115.            
  116.             return $this;
  117.             }
  118.            
  119.            
  120.            
  121.             public function make_tag($data, $value, $record = self::RECORD)
  122.             {
  123.             $length = strlen($value);
  124.             $retval = chr(0x1C) . chr($record) . chr($data);
  125.            
  126.             if($length < 0x8000)
  127.             {
  128.                 $retval .= chr($length >> 8) .  chr($length & 0xFF);
  129.             }
  130.             else
  131.             {
  132.                 $retval .= chr(0x80) .
  133.                            chr(0x04) .
  134.                            chr(($length >> 24) & 0xFF) .
  135.                            chr(($length >> 16) & 0xFF) .
  136.                            chr(($length >> 8) & 0xFF) .
  137.                            chr($length & 0xFF);
  138.             }
  139.            
  140.             return $retval . $value;
  141.             }
  142.            
  143.            
  144.     }
  145.  
  146.  
  147. // using
  148.  
  149.  
  150.  
  151.  
  152.  
  153.         public function cache_Source($quality = 70)
  154.         {
  155.             $dest = ILLI_Constructeur::get_Instance(self::c_CNSTDR)->_APP->_CACHE_IMAGES.$this->get_CryptFile().$this->extension;
  156.            
  157.             if(TRUE === is_animgif($f = file_get_contents($this->file)))
  158.             {
  159.                 //if(TRUE === @chmod(ILLI_Constructeur::get_Instance(self::c_CNSTDR)->_APP->_CACHE_IMAGES, 0777))
  160.                     file_put_contents($dest, $f);
  161.                    
  162.                 return $f;
  163.             }
  164.            
  165.            
  166.            
  167.             ob_start();
  168.             switch($this->type)
  169.             {
  170.                 case 'png':
  171.                
  172.                     $this->png($dest);
  173.                    
  174.                     break;
  175.                    
  176.                 case 'jpeg':
  177.                    
  178.                    
  179.                     $this->jpeg($dest, $quality);
  180.                    
  181.                    
  182.                    
  183.                     $IPCT = new ILLI_Container_Api_Image_Iptc;
  184.                    
  185.                     $IPCT
  186.                     ->set_caption('foobar')
  187.                     ->set_copyright('fruffl')
  188.                     ->save($dest);
  189.  
  190.                     break;
  191.                    
  192.                 case 'gif':
  193.                
  194.                     $this->gif($dest);
  195.                    
  196.                     break;
  197.                    
  198.                 default:
  199.                
  200.                     $this->generate_ErrorImage();
  201.             }
  202.            
  203.             return ob_get_clean();
  204.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement