function testThisDoesNotWorkAsExpected() { $subject = "Превед, медвед!"; $data = new PelDataWindow(file_get_contents($this->file)); if (PelJpeg::isValid($data)) { $jpeg = new PelJpeg(); $jpeg->load($data); $exif = $jpeg->getExif(); if (null == $exif) { $exif = new PelExif(); $jpeg->setExif($exif); $tiff = new PelTiff(); $exif->setTiff($tiff); } $tiff = $exif->getTiff(); $ifd0 = $tiff->getIfd(); if (null == $ifd0) { $ifd0 = new PelIfd(PelIfd::IFD0); $tiff->setIfd($ifd0); } } $ifd0->addEntry(new PelEntryWindowsString(PelTag::XP_SUBJECT, $subject)); file_put_contents($this->file, $jpeg->getBytes()); $jpeg = new PelJpeg($this->file); $exif = $jpeg->getExif(); $tiff = $exif->getTiff(); $ifd0 = $tiff->getIfd(); $written_subject = $ifd0->getEntry(PelTag::XP_SUBJECT); $this->assertEqual($subject, $written_subject->getValue()); }
public function saveEdit($file, $name, $options = array(), $quality = 100) { // Check for request forgeries WFToken::checkToken() or die('Access to this resource is restricted'); // check for image editor access if ($this->checkAccess('image_editor', 1) === false) { JError::raiseError(403, 'Access to this resource is restricted'); } $browser = $this->getBrowser(); $filesystem = $browser->getFileSystem(); // check file self::validateImagePath($file); // clean temp $this->cleanEditorTmp($file, false); // check new name self::validateImagePath($name); $upload = JRequest::getVar('file', '', 'files', 'array'); // create a filesystem result object $result = new WFFileSystemResult(); if (isset($upload) && isset($upload['tmp_name']) && is_uploaded_file($upload['tmp_name'])) { $tmp = $upload['tmp_name']; self::validateImageFile($tmp); $exif = null; // get exif data from orignal file if (preg_match('#\\.jp(eg|g)$#i', basename($file)) && basename($file) == basename($name)) { // load exif classes require_once dirname(__FILE__) . '/pel/PelJpeg.php'; $src = WFUtility::makePath($filesystem->getBaseDir(), $file); $jpeg = new PelJpeg($src); $exif = $jpeg->getExif(); } $result = $filesystem->upload('multipart', trim($tmp), dirname($file), basename($name)); if ($result->state === true && $exif) { $pel = new PelDataWindow($result->path); if (PelJpeg::isValid($pel)) { $jpeg = new PelJpeg(); $jpeg->load($pel); $jpeg->setExif($exif); //$jpeg->saveFile($result->path); // write to file JFile::write($result->path, $jpeg->getBytes()); } } @unlink($tmp); } else { // set upload as false - JSON request $upload = false; $file = WFUtility::makePath($filesystem->getBaseDir(), $file); $dest = dirname($file) . '/' . basename($name); // get extension $ext = WFUtility::getExtension($dest); // load image class require_once dirname(__FILE__) . '/image/image.php'; // create image $image = new WFImage($file, $this->getParam('prefer_imagick', true)); foreach ($options as $filter) { if (isset($filter->task)) { $args = isset($filter->args) ? (array) $filter->args : array(); switch ($filter->task) { case 'resize': $w = $args[0]; $h = $args[1]; $image->resize($w, $h); break; case 'crop': $w = $args[0]; $h = $args[1]; $x = $args[2]; $y = $args[3]; $image->crop($w, $h, $x, $y); break; case 'rotate': $image->rotate(array_shift($args)); break; case 'flip': $image->flip(array_shift($args)); break; default: $image->filter($filter->task, $args); break; } } } // get image data $data = $image->toString($ext); // write to file if ($data) { $result->state = (bool) @JFile::write($dest, $data); } // set path $result->path = $dest; } if ($result->state === true) { // check if its a valid image if (@getimagesize($result->path) === false) { JFile::delete($result->path); throw new InvalidArgumentException('Invalid image file'); } else { $result->path = str_replace(WFUtility::cleanPath(JPATH_SITE), '', $result->path); $browser->setResult(WFUtility::cleanPath($result->path, '/'), 'files'); } } else { $browser->setResult($result->message || WFText::_('WF_IMGMANAGER_EXT_EDIT_SAVE_ERROR'), 'error'); } // set header and exit if ($upload) { header("Expires: Wed, 4 Apr 1984 13:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M_Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); die(json_encode($browser->getResult())); } // return to WFRequest return $browser->getResult(); }
println('Usage: %s [-d] <file> ...', $prog); println('Optional arguments:'); println(' -d turn debug output on.'); println('Mandatory arguments:'); println(' file ... one or more file names.'); exit(1); } /* We typically need lots of RAM to parse TIFF images since they tend * to be big and uncompressed. */ ini_set('memory_limit', '32M'); foreach ($argv as $file) { println('Reading file "%s".', $file); $data = new PelDataWindow(file_get_contents($file)); if (PelJpeg::isValid($data)) { $jpeg = new PelJpeg(); $jpeg->load($data); $app1 = $jpeg->getExif(); if ($app1 == null) { println('Skipping %s because no APP1 section was found.', $file); continue; } $tiff = $app1->getTiff(); } elseif (PelTiff::isValid($data)) { $tiff = new PelTiff($data); } else { println('Unrecognized image format! Skipping.'); continue; } $ifd0 = $tiff->getIfd(); $entry = $ifd0->getEntry(PelTag::DATE_TIME); if ($entry == null) {
public function exifOrientation($input_file, $output_file) { $data = new PelDataWindow(file_get_contents($input_file)); if (PelJpeg::isValid($data)) { $jpeg = new PelJpeg(); $jpeg->load($data); if ($jpeg != null) { $exif = $jpeg->getExif(); if ($exif != null) { $tiff = $exif->getTiff(); if ($tiff != null) { $ifd0 = $tiff->getIfd(); if ($ifd0 != null) { $orientation = $ifd0->getEntry(PelTag::ORIENTATION); $orientation->setValue(0); $sEXIF_description = "Picture rotated automatically."; $description = $ifd0->getEntry(PelTag::IMAGE_DESCRIPTION); if ($description == null) { $description = new PelEntryAscii(PelTag::IMAGE_DESCRIPTION, $sEXIF_description); $ifd0->addEntry($description); } else { $sEXIF_description_old = $description->getValue(); $description->setValue($sEXIF_description); } file_put_contents($output_file, $jpeg->getBytes()); } } } } } }
public function exifOrientation($input_file, $output_file) { $data = new PelDataWindow(file_get_contents($input_file)); if (PelJpeg::isValid($data)) { $jpeg = new PelJpeg(); $jpeg->load($data); if ($jpeg != null) { $exif = $jpeg->getExif(); if ($exif != null) { $tiff = $exif->getTiff(); if ($tiff != null) { $ifd0 = $tiff->getIfd(); if ($ifd0 != null) { // change tag "orientation" $orientation = $ifd0->getEntry(PelTag::ORIENTATION); $orientation->setValue(0); //$orientation->getValue(); // Change tag "image_description" $sEXIF_description = "Picture rotated automatically."; $description = $ifd0->getEntry(PelTag::IMAGE_DESCRIPTION); // We need to check if the image already had a description stored. if ($description == null) { // Create a new PelEntryAscii object to hold the description. $description = new PelEntryAscii(PelTag::IMAGE_DESCRIPTION, $sEXIF_description); // This will insert the newly created entry with the description into the IFD. $ifd0->addEntry($description); } else { // Save old description found in the image $sEXIF_description_old = $description->getValue(); // Update description $description->setValue($sEXIF_description); } // write file file_put_contents($output_file, $jpeg->getBytes()); } } } } } }
function saveEdit() { // check for image editor access if (!$this->checkAccess('image_editor', 1)) { JError::raiseError(403, 'RESTRICTED ACCESS'); } $editor = $this->getImageEditor(); $browser = $this->getBrowser(); $args = func_get_args(); // file src $file = array_shift($args); // check file WFUtility::checkPath($file); // file name $name = array_shift($args); // check name WFUtility::checkPath($name); // check for extension in destination name if (preg_match('#\\.(php|php(3|4|5)|phtml|pl|py|jsp|asp|htm|html|shtml|sh|cgi)\\b#i', $name)) { JError::raiseError(403, 'INVALID FILE NAME'); } // edit data $props = array_shift($args); // exif data $exif = null; $data = JRequest::getVar('data', '', 'POST', 'STRING', JREQUEST_ALLOWRAW); if (preg_match('#data:image\\/(jpeg|jpg|png|bmp);base64#', $data)) { // replace spaces $data = str_replace(' ', '+', $data); // remove header $data = substr($data, strpos($data, ",") + 1); // decode data $data = base64_decode($data); $src = WFUtility::makePath(JPATH_SITE, $file); $dest = dirname($src) . DS . basename($name); // get exif data from orignal file if (preg_match('#\\.jp(eg|g)$#i', basename($file)) && basename($file) == basename($dest)) { // load exif classes require_once dirname(__FILE__) . DS . 'pel' . DS . 'PelJpeg.php'; $jpeg = new PelJpeg($src); $exif = $jpeg->getExif(); } if (!JFile::write($dest, $data)) { $browser->setResult(WFText::_('WF_IMGMANAGER_EXT_ERROR'), 'error'); } else { $browser->setResult(basename($dest), 'files'); if ($exif && basename($file) == basename($dest)) { $pel = new PelDataWindow($data); if (PelJpeg::isValid($pel)) { $jpeg = new PelJpeg(); $jpeg->load($pel); /*$dim = @getimagesize($dest); if ($dim) { $tiff = $exif->getTiff(); $ifd0 = $tiff->getIfd(); $width = $ifd0->getEntry(PelTag::IMAGE_WIDTH); $height = $ifd0->getEntry(PelTag::IMAGE_LENGTH); $width->setValue($dim[0]); $height->setValue($dim[1]); }*/ $jpeg->setExif($exif); $jpeg->saveFile($dest); } } } } else { $browser->setResult(WFText::_('WF_IMGMANAGER_EXT_ERROR'), 'error'); } return $browser->getResult(); }