public function edytujAction()
 {
     $this->_helper->layout()->disableLayout();
     if ($this->getRequest()->isPost()) {
         $pole = $this->getRequest()->getParam('pole');
         $wartosc = $this->getRequest()->getParam('value');
         $id_zdjec_string = $this->getRequest()->getParam('id');
         $id_zdjec = array_filter(explode(' ', $id_zdjec_string));
         foreach ($id_zdjec as $id_zdjecia) {
             //pobranie aktualnych metadanych z bazy
             $photoMapper = Model_PhotoMapper::getInstance();
             $metadane = $photoMapper->Metadane($id_zdjecia);
             $id_katalogu = $metadane->getCatalogsId();
             //pobranie ścieżki do zdjęcia
             $catalogMapper = Model_CatalogMapper::getInstance();
             $katalog = $catalogMapper->katalog($id_katalogu);
             $file = $katalog->getPath() . '/' . $metadane->getFilename();
             //edycja metadanych w zdjęciu
             $iptc = new Model_Iptc();
             $iptc->iptc($file);
             //ustawienie nowych wartości i zapis metadanych do zdjęcia
             switch ($pole) {
                 case 'filename':
                     $metadane->setFilename($wartosc);
                     $file_new = $katalog->getPath() . '/' . $wartosc;
                     rename($file, $file_new);
                     break;
                 case 'headline':
                     $metadane->setHeadline($wartosc);
                     $iptc->set(IPTC_HEADLINE, $wartosc);
                     $iptc->write();
                     break;
                 case 'caption':
                     $metadane->setCaption($wartosc);
                     $iptc->set(IPTC_CAPTION, $wartosc);
                     $iptc->write();
                     break;
                 case 'writer':
                     $metadane->setWriter($wartosc);
                     $iptc->set(IPTC_WRITER, $wartosc);
                     $iptc->write();
                     break;
                 case 'copyrigthNotice':
                     $metadane->setCopyrightNotice($wartosc);
                     $iptc->set(IPTC_COPYRIGHT_NOTICE, $wartosc);
                     $iptc->write();
                     break;
                 case 'contact':
                     $metadane->setContact($wartosc);
                     $iptc->set(IPTC_CONTACT, $wartosc);
                     $iptc->write();
                     break;
                 case 'objectName':
                     $metadane->setObjectName($wartosc);
                     $iptc->set(IPTC_OBJECT_NAME, $wartosc);
                     $iptc->write();
                     break;
                 case 'byLineTitle':
                     $metadane->setByLineTitle($wartosc);
                     $iptc->set(IPTC_BYLINE_TITLE, $wartosc);
                     $iptc->write();
                     break;
                 case 'city':
                     $metadane->setCity($wartosc);
                     $iptc->set(IPTC_CITY, $wartosc);
                     $iptc->write();
                     break;
                 case 'subLocation':
                     $metadane->setSubLocation($wartosc);
                     $iptc->set(IPTC_SUB_LOCATION, $wartosc);
                     $iptc->write();
                     break;
                 case 'province':
                     $metadane->setProvince($wartosc);
                     $iptc->set(IPTC_PROVINCE_STATE, $wartosc);
                     $iptc->write();
                     break;
                 case 'countryCode':
                     $metadane->setCountryCode($wartosc);
                     $iptc->set(IPTC_COUNTRY_CODE, $wartosc);
                     $iptc->write();
                     break;
                 case 'country':
                     $metadane->setCountry($wartosc);
                     $iptc->set(IPTC_COUNTRY, $wartosc);
                     $iptc->write();
                     break;
                 case 'keywords':
                     $dopisz = strcmp('*', $wartosc[0]);
                     if ($dopisz == 0) {
                         $slowa_kluczowe = substr($wartosc, 1);
                         $poprzednio = $metadane->getKeywords();
                         $metadane->setKeywords($poprzednio . ' ' . $slowa_kluczowe);
                         $iptc->set(IPTC_KEYWORDS, $poprzednio . ' ' . $slowa_kluczowe);
                     } else {
                         $metadane->setKeywords($wartosc);
                         $iptc->set(IPTC_KEYWORDS, $wartosc);
                     }
                     $iptc->write();
                     break;
                 default:
                     break;
             }
             //zapis do bazy
             $photoMapper->save($metadane);
         }
         $this->view->wartosc = $wartosc;
     }
 }
示例#2
0
 /**
  * Pobranie metadanych ze zdjęcia
  *
  */
 public function pobierzMetadane($file, $filename, $catalogId)
 {
     $this->setCatalogsId($catalogId);
     $this->setFilename($filename);
     //Odczyt danych IPTC z pliku
     $iptc = new Model_Iptc();
     $iptc->iptc($file);
     $this->setHeadline($iptc->get(IPTC_HEADLINE));
     $this->setCaption($iptc->get(IPTC_CAPTION));
     $this->setWriter($iptc->get(IPTC_WRITER));
     $this->setCopyrightNotice($iptc->get(IPTC_COPYRIGHT_NOTICE));
     $this->setContact($iptc->get(IPTC_CONTACT));
     $this->setObjectName($iptc->get(IPTC_OBJECT_NAME));
     $this->setByLineTitle($iptc->get(IPTC_BYLINE_TITLE));
     $this->setCity($iptc->get(IPTC_CITY));
     $this->setSubLocation($iptc->get(IPTC_SUB_LOCATION));
     $this->setProvince($iptc->get(IPTC_PROVINCE_STATE));
     $this->setCountryCode($iptc->get(IPTC_COUNTRY_CODE));
     $this->setCountry($iptc->get(IPTC_COUNTRY));
     $this->setKeywords($iptc->get(IPTC_KEYWORDS));
     //Odczyt danych EXIF z pliku za pomocą exif_reader()
     $modelExif = new Model_Exif();
     $modelExif->exif($file);
     $this->setFilesize($modelExif->get('FILE', 'FileSize'));
     $this->setMimeType($modelExif->get('FILE', 'MimeType'));
     $this->setHeight($modelExif->get('COMPUTED', 'Height'));
     $this->setWidth($modelExif->get('COMPUTED', 'Width'));
     //Odczyt danych EXIF z pliku za pomocą PEL (PHP Exif Library)
     //        include_once('C:\xampp\php\PEAR\PelJpeg.php');
     require_once 'pel-0.9.1/PelJpeg.php';
     $jpeg = new PelJpeg($file);
     $data = $jpeg->getExif();
     if ($data) {
         $ifd0 = $data->getTiff()->getIfd();
         $exif = $ifd0->getSubIfd(PelIfd::EXIF);
         $gps = $ifd0->getSubIfd(PelIfd::GPS);
         //ifd0
         if ($ifd0) {
             if ($tag = $ifd0->getEntry(PelTag::MAKE)) {
                 $this->setMake($tag->getText());
             }
             if ($tag = $ifd0->getEntry(PelTag::MODEL)) {
                 $this->setModel($tag->getText());
             }
             if ($tag = $ifd0->getEntry(PelTag::ORIENTATION)) {
                 $this->setOrientation($tag->getText());
             }
             if ($tag = $ifd0->getEntry(PelTag::X_RESOLUTION)) {
                 $this->setXResolution($tag->getText());
             }
             if ($tag = $ifd0->getEntry(PelTag::Y_RESOLUTION)) {
                 $this->setYResolution($tag->getText());
             }
         }
         //exif
         if ($exif) {
             if ($tag = $exif->getEntry(PelTag::DATE_TIME_ORIGINAL)) {
                 $this->setDateTimeOriginal($tag->getText());
             }
             if ($tag = $exif->getEntry(PelTag::EXPOSURE_TIME)) {
                 $this->setExposureTime($tag->getText());
             }
             if ($tag = $exif->getEntry(PelTag::EXPOSURE_PROGRAM)) {
                 $this->setExposureProgram($tag->getText());
             }
             if ($tag = $exif->getEntry(PelTag::EXPOSURE_MODE)) {
                 $this->setExposureMode($tag->getText());
             }
             if ($tag = $exif->getEntry(PelTag::FNUMBER)) {
                 $this->setFNumber($tag->getText());
             }
             if ($tag = $exif->getEntry(PelTag::FOCAL_LENGTH)) {
                 $this->setFocalLength($tag->getText());
             }
             if ($tag = $exif->getEntry(PelTag::ISO_SPEED_RATINGS)) {
                 $this->setIsoSpeedRatings($tag->getText());
             }
             if ($tag = $exif->getEntry(PelTag::LIGHT_SOURCE)) {
                 $this->setLightSource($tag->getText());
             }
             if ($tag = $exif->getEntry(PelTag::FLASH)) {
                 $this->setFlash($tag->getText());
             }
             if ($tag = $exif->getEntry(PelTag::WHITE_BALANCE)) {
                 $this->setWhiteBalance($tag->getText());
             }
             if ($tag = $exif->getEntry(PelTag::DIGITAL_ZOOM_RATIO)) {
                 $this->setDigitalZoomRatio($tag->getText());
             }
         }
         //gps
         if ($gps) {
             $this->setGpsLatitudeRef($gps->getEntry(PelTag::GPS_LATITUDE_REF)->getText());
             $this->setGpsLatitude(substr($gps->getEntry(PelTag::GPS_LATITUDE)->getText(), -7, 5));
             $this->setGpsLongitudeRef($gps->getEntry(PelTag::GPS_LONGITUDE_REF)->getText());
             $this->setGpsLongitude(substr($gps->getEntry(PelTag::GPS_LONGITUDE)->getText(), -7, 5));
         }
     }
 }