/** * Add GPS information to an image basic metadata. Any old Exif data * is discarded. * * @param string the input filename. * * @param string the output filename. An updated copy of the input * image is saved here. * * @param string image description. * * @param string user comment. * * @param string camera model. * * @param float longitude expressed as a fractional number of degrees, * e.g. 12.345°. Negative values denotes degrees west of Greenwich. * * @param float latitude expressed as for longitude. Negative values * denote degrees south of equator. * * @param float the altitude, negative values express an altitude * below sea level. * * @param string the date and time. */ function addGpsInfo($input, $output, $description, $comment, $model, $longitude, $latitude, $altitude, $date_time) { /* Load the given image into a PelJpeg object */ $jpeg = new PelJpeg($input); /* Create and add empty Exif data to the image (this throws away any * old Exif data in the image). */ $exif = new PelExif(); $jpeg->setExif($exif); /* Create and add TIFF data to the Exif data (Exif data is actually * stored in a TIFF format). */ $tiff = new PelTiff(); $exif->setTiff($tiff); /* Create first Image File Directory and associate it with the TIFF * data. */ $ifd0 = new PelIfd(PelIfd::IFD0); $tiff->setIfd($ifd0); /* Create a sub-IFD for holding GPS information. GPS data must be * below the first IFD. */ $gps_ifd = new PelIfd(PelIfd::GPS); $ifd0->addSubIfd($gps_ifd); /* The USER_COMMENT tag must be put in a Exif sub-IFD under the * first IFD. */ $exif_ifd = new PelIfd(PelIfd::EXIF); $exif_ifd->addEntry(new PelEntryUserComment($comment)); $ifd0->addSubIfd($exif_ifd); $inter_ifd = new PelIfd(PelIfd::INTEROPERABILITY); $ifd0->addSubIfd($inter_ifd); $ifd0->addEntry(new PelEntryAscii(PelTag::MODEL, $model)); $ifd0->addEntry(new PelEntryAscii(PelTag::DATE_TIME, $date_time)); $ifd0->addEntry(new PelEntryAscii(PelTag::IMAGE_DESCRIPTION, $description)); $gps_ifd->addEntry(new PelEntryByte(PelTag::GPS_VERSION_ID, 2, 2, 0, 0)); /* Use the convertDecimalToDMS function to convert the latitude from * something like 12.34° to 12° 20' 42" */ list($hours, $minutes, $seconds) = convertDecimalToDMS($latitude); /* We interpret a negative latitude as being south. */ $latitude_ref = $latitude < 0 ? 'S' : 'N'; $gps_ifd->addEntry(new PelEntryAscii(PelTag::GPS_LATITUDE_REF, $latitude_ref)); $gps_ifd->addEntry(new PelEntryRational(PelTag::GPS_LATITUDE, $hours, $minutes, $seconds)); /* The longitude works like the latitude. */ list($hours, $minutes, $seconds) = convertDecimalToDMS($longitude); $longitude_ref = $longitude < 0 ? 'W' : 'E'; $gps_ifd->addEntry(new PelEntryAscii(PelTag::GPS_LONGITUDE_REF, $longitude_ref)); $gps_ifd->addEntry(new PelEntryRational(PelTag::GPS_LONGITUDE, $hours, $minutes, $seconds)); /* Add the altitude. The absolute value is stored here, the sign is * stored in the GPS_ALTITUDE_REF tag below. */ $gps_ifd->addEntry(new PelEntryRational(PelTag::GPS_ALTITUDE, array(abs($altitude), 1))); /* The reference is set to 1 (true) if the altitude is below sea * level, or 0 (false) otherwise. */ $gps_ifd->addEntry(new PelEntryByte(PelTag::GPS_ALTITUDE_REF, (int) ($altitude < 0))); /* Finally we store the data in the output file. */ file_put_contents($output, $jpeg->getBytes()); }
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()); }
function addGPSdata($infile, $outfile, $GPS_lat, $GPS_lon, $GPS_alt) { try { $image = new PelJpeg($infile); } catch (Exception $exc) { return -1; } if ($image instanceof PelJpeg) { if ($image->isValid(new PelDataWindow($image->getBytes()))) { $exif = $image->getExif(); if ($exif == null) { $exif = new PelExif(); $image->setExif($exif); $exif->setTiff(new PelTiff()); } $tiff = $exif->getTiff(); $ifd0 = $tiff->getIfd(); if ($ifd0 == null) { $ifd0 = new PelIFD(PelIfd::IFD0); $tiff->setIfd($ifd0); } /* Tags erzeugen */ $subifd = new PelIfd(PelIfd::GPS); $GPS_latref = $GPS_lat < 0 ? "S" : "N"; $GPS_lonref = $GPS_lon < 0 ? "W" : "E"; $GPS_altref = $GPS_alt < 0 ? 1 : 0; list($degrees, $minutes, $milliseconds) = dec2dms(abs($GPS_lat)); $gpslat = new PelEntryRational(PelTag::GPS_LATITUDE, array($degrees, 1), array($minutes, 1), array($milliseconds, 1000)); list($degrees, $minutes, $milliseconds) = dec2dms(abs($GPS_lon)); $gpslon = new PelEntryRational(PelTag::GPS_LONGITUDE, array($degrees, 1), array($minutes, 1), array($milliseconds, 1000)); echo $GPS_alt * 1000; $gpsalt = new PelEntryRational(PelTag::GPS_ALTITUDE, array(abs($GPS_alt * 1000), 1000)); $gpslatref = new PelEntryAscii(PelTag::GPS_LATITUDE_REF, $GPS_latref); $gpslonref = new PelEntryAscii(PelTag::GPS_LONGITUDE_REF, $GPS_lonref); $gpsaltref = new PelEntryByte(PelTag::GPS_ALTITUDE_REF, $GPS_altref); $gpsversion = new PelEntryByte(PelTag::GPS_VERSION_ID, 2, 2, 0, 0); /* Daten eintragen.*/ $subifd->addEntry($gpsversion); $subifd->addEntry($gpslat); $subifd->addEntry($gpslon); $subifd->addEntry($gpsalt); $subifd->addEntry($gpslatref); $subifd->addEntry($gpslonref); $subifd->addEntry($gpsaltref); $ifd0->addSubIfd($subifd); file_put_contents($outfile, $image->getBytes()); return 0; } } return -1; }
function testThisDoesNotWorkAsExpected() { $tmpfile = dirname(__FILE__) . '/images/bug1730993_tmp.jpg'; $bigfile = dirname(__FILE__) . '/images/bug1730993_large.jpg'; try { $jpeg = new PelJpeg($tmpfile); // the error occurs here $exif = $jpeg->getExif(); if ($exif != null) { $jpeg1 = new PelJpeg($bigfile); $jpeg1->setExif($exif); file_put_contents($bigfile, $jpeg1->getBytes()); } } catch (Exception $e) { $this->fail('Test should not throw an exception'); } }
function testThisDoesNotWorkAsExpected() { $filename = dirname(__FILE__) . '/images/bug3017880.jpg'; try { $exif = null; $success = 1; // return true by default, as this function may not resave the file, but it's still success $resave_file = 0; $jpeg = new PelJpeg($filename); // should all exif data on photo be cleared (gd and iu will always strip it anyway, so only // force strip if you know the image you're branding is an original) //$jpeg->clearExif(); if ($exif === null) { $exif = new PelExif(); $jpeg->setExif($exif); $tiff = new PelTiff(); $exif->setTiff($tiff); } $tiff = $exif->getTiff(); $ifd0 = $tiff->getIfd(); if ($ifd0 == null) { $ifd0 = new PelIfd(PelIfd::IFD0); $tiff->setIfd($ifd0); } $software_name = 'Example V2'; $software = $ifd0->getEntry(PelTag::SOFTWARE); if ($software == null) { $software = new PelEntryAscii(PelTag::SOFTWARE, $software_name); $ifd0->addEntry($software); $resave_file = 1; echo 'null'; } else { $software->setValue($software_name); $resave_file = 1; echo 'update'; } if ($resave_file == 1 && !file_put_contents($filename, $jpeg->getBytes())) { // if it was okay to resave the file, but it did not save correctly $success = 0; } } catch (Exception $e) { $this->fail('Test should not throw an exception'); } }
function testThisDoesNotWorkAsExpected() { $scale = 0.75; $input_jpeg = new PelJpeg($this->file); $original = ImageCreateFromString($input_jpeg->getBytes()); $original_w = ImagesX($original); $original_h = ImagesY($original); $scaled_w = $original_w * $scale; $scaled_h = $original_h * $scale; $scaled = ImageCreateTrueColor($scaled_w, $scaled_h); ImageCopyResampled($scaled, $original, 0, 0, 0, 0, $scaled_w, $scaled_h, $original_w, $original_h); $output_jpeg = new PelJpeg($scaled); $exif = $input_jpeg->getExif(); if ($exif != null) { $output_jpeg->setExif($exif); } file_put_contents($this->file, $output_jpeg->getBytes()); $jpeg = new PelJpeg($this->file); $exifin = $jpeg->getExif(); $this->assertEqual($exif, $exifin); }
function testWriteRead() { Pel::setStrictParsing(true); $ifd = new PelIfd(PelIfd::IFD0); $this->assertTrue($ifd->isLastIfd()); foreach ($this->entries as $entry) { $ifd->addEntry($entry); } $tiff = new PelTiff(); $this->assertNull($tiff->getIfd()); $tiff->setIfd($ifd); $this->assertNotNull($tiff->getIfd()); $exif = new PelExif(); $this->assertNull($exif->getTiff()); $exif->setTiff($tiff); $this->assertNotNull($exif->getTiff()); $jpeg = new PelJpeg(dirname(__FILE__) . '/no-exif.jpg'); $this->assertNull($jpeg->getExif()); $jpeg->setExif($exif); $this->assertNotNull($jpeg->getExif()); $jpeg->saveFile('test-output.jpg'); $this->assertTrue(file_exists('test-output.jpg')); $this->assertTrue(filesize('test-output.jpg') > 0); /* Now read the file and see if the entries are still there. */ $jpeg = new PelJpeg('test-output.jpg'); $exif = $jpeg->getExif(); $this->assertIsA($exif, 'PelExif'); $tiff = $exif->getTiff(); $this->assertIsA($tiff, 'PelTiff'); $ifd = $tiff->getIfd(); $this->assertIsA($ifd, 'PelIfd'); $this->assertEqual($ifd->getType(), PelIfd::IFD0); $this->assertTrue($ifd->isLastIfd()); foreach ($this->entries as $entry) { $this->assertEqual($ifd->getEntry($entry->getTag())->getValue(), $entry->getValue()); } unlink('test-output.jpg'); }
/** * Copy the source image's EXIF information to the new file in the cache * * @since 2.0 * @uses PEL * @param string $cacheFilePath * @return mixed string contents of image on success, false on failure */ private function copyEXIF($cacheFilePath) { $pelJpegLib = dirname(__FILE__) . '/../pel/src/PelJpeg.php'; // Linking to pel library will break MIT license // Make the EXIF copy optional if (file_exists($pelJpegLib)) { // Make sure to suppress strict warning thrown by PEL require_once $pelJpegLib; $jpeg = new PelJpeg($this->getSource()->getFullPath()); $exif = $jpeg->getExif(); if ($exif !== null) { $jpeg = new PelJpeg($cacheFilePath); $jpeg->setExif($exif); $imageData = $jpeg->getBytes(); if (!file_put_contents($cacheFilePath, $imageData)) { return false; } return $imageData; } } return file_get_contents($cacheFilePath); }
/** * Copy the source image's EXIF information to the new file in the cache * * @since 2.0 * @uses PEL * @param string $cacheFilePath * @return mixed string contents of image on success, FALSE on failure */ private function copyEXIF($cacheFilePath) { // Make sure to suppress strict warning thrown by PEL @(require_once dirname(__FILE__) . '/pel-0.9.2/src/PelJpeg.php'); $jpeg = new PelJpeg($this->source->fullPath()); $exif = $jpeg->getExif(); if ($exif) { $jpeg = new PelJpeg($cacheFilePath); $jpeg->setExif($exif); $imageData = $jpeg->getBytes(); if (!file_put_contents($cacheFilePath, $imageData)) { return FALSE; } return $imageData; } // if return file_get_contents($cacheFilePath); }
public static function attach_exif($jpegfile, $option) { require_once FS_ROOT . 'include/PEL/PelJpeg.php'; $jpeg = new PelJpeg($jpegfile); $exif = new PelExif(); $jpeg->setExif($exif); $tiff = new PelTiff(); $exif->setTiff($tiff); $ifd0 = new PelIfd(PelIfd::IFD0); $tiff->setIfd($ifd0); if (isset($option['orientation']) && $option['orientation'] > 0) { $ifd0->addEntry(new PelEntryShort(PelTag::ORIENTATION, intval($option['orientation']))); } // $exif_ifd = new PelIfd(PelIfd::EXIF); // $exif_ifd->addEntry(new PelEntryUserComment('Hello World!')); // $ifd0->addSubIfd($exif_ifd); file_put_contents($jpegfile, $jpeg->getBytes()); }
/** * Copy the source image's EXIF information to the new file in the cache * * @since 2.0 * @uses PEL * @param string $cacheFilePath * @return mixed string contents of image on success, false on failure */ private function copyEXIF($cacheFilePath) { // Make sure to suppress strict warning thrown by PEL require_once dirname(__FILE__) . '/../pel/src/PelJpeg.php'; $jpeg = new PelJpeg($this->getSource()->getFullPath()); $exif = $jpeg->getExif(); if ($exif !== null) { $jpeg = new PelJpeg($cacheFilePath); $jpeg->setExif($exif); $imageData = $jpeg->getBytes(); if (!file_put_contents($cacheFilePath, $imageData)) { return false; } return $imageData; } // if return file_get_contents($cacheFilePath); }
println(' input the input filename, a JPEG image.'); println(' output filename for saving the changed image.'); println(' scale scale factor, say 0.5 to resize to half the ' . 'original size.'); exit(1); } /* The input file is now loaded into a PelJpeg object. */ println('Reading file "%s".', $input); $input_jpeg = new PelJpeg($input); /* The input image is already loaded, so we can reuse the bytes stored * in $input_jpeg when creating the Image resource. */ $original = ImageCreateFromString($input_jpeg->getBytes()); $original_w = ImagesX($original); $original_h = ImagesY($original); $scaled_w = $original_w * $scale; $scaled_h = $original_h * $scale; /* Now create the scaled image. */ $scaled = ImageCreateTrueColor($scaled_w, $scaled_h); ImageCopyResampled($scaled, $original, 0, 0, 0, 0, $scaled_w, $scaled_h, $original_w, $original_h); /* We want the raw JPEG data from $scaled. Luckily, one can create a * PelJpeg object from an image resource directly: */ $output_jpeg = new PelJpeg($scaled); /* Retrieve the original Exif data in $jpeg (if any). */ $exif = $input_jpeg->getExif(); /* If no Exif data was present, then $exif is null. */ if ($exif != null) { $output_jpeg->setExif($exif); } /* We can now save the scaled image. */ println('Writing file "%s".', $output); file_put_contents($output, $output_jpeg->getBytes()); /* The End. */
/** * Add GPS information to an image basic metadata. Any old Exif data * is discarded. * * @param string the input filename. * * @param string the output filename. An updated copy of the input * image is saved here. * * @param string image description. * * @param string user comment. * * @param string camera model. * * @param float longitude expressed as a fractional number of degrees, * e.g. 12.345°. Negative values denotes degrees west of Greenwich. * * @param float latitude expressed as for longitude. Negative values * denote degrees south of equator. * * @param float the altitude, negative values express an altitude * below sea level. * * @param string the date and time. */ function addGpsInfo($input, $description, $comment, $artist, $make, $model, $longitude, $latitude) { /* Load the given image into a PelJpeg object */ $jpeg = new PelJpeg($input); /* Create and add empty Exif data to the image (this throws away any * old Exif data in the image). */ $exif = new PelExif(); $jpeg->setExif($exif); /* Create and add TIFF data to the Exif data (Exif data is actually * stored in a TIFF format). */ $tiff = new PelTiff(); $exif->setTiff($tiff); /* Create first Image File Directory and associate it with the TIFF * data. */ $ifd0 = new PelIfd(PelIfd::IFD0); $tiff->setIfd($ifd0); /* Create a sub-IFD for holding GPS information. GPS data must be * below the first IFD. */ $gps_ifd = new PelIfd(PelIfd::GPS); $ifd0->addSubIfd($gps_ifd); /* The USER_COMMENT tag must be put in a Exif sub-IFD under the * first IFD. */ $exif_ifd = new PelIfd(PelIfd::EXIF); $exif_ifd->addEntry(new PelEntryUserComment($comment)); $ifd0->addSubIfd($exif_ifd); $inter_ifd = new PelIfd(PelIfd::INTEROPERABILITY); $ifd0->addSubIfd($inter_ifd); $ifd0->addEntry(new PelEntryAscii(PelTag::ARTIST, $artist)); $ifd0->addEntry(new PelEntryAscii(PelTag::MAKE, $make)); $ifd0->addEntry(new PelEntryAscii(PelTag::MODEL, $model)); $ifd0->addEntry(new PelEntryAscii(PelTag::IMAGE_DESCRIPTION, $description)); $gps_ifd->addEntry(new PelEntryByte(PelTag::GPS_VERSION_ID, 2, 2, 0, 0)); // Negative numbers indicate different reference then the usual N/E if ($longitude < 0) { $longitude_ref = 'W'; } else { $longitude_ref = 'E'; } if ($latitude < 0) { $latitude_ref = 'S'; } else { $latitude_ref = 'N'; } list($h, $m, $s) = convertDecimalToDMS($latitude); $gps_ifd->addEntry(new PelEntryAscii(PelTag::GPS_LATITUDE_REF, $latitude_ref)); $gps_ifd->addEntry(new PelEntryRational(PelTag::GPS_LATITUDE, $h, $m, $s)); list($h, $m, $s) = convertDecimalToDMS($longitude); $gps_ifd->addEntry(new PelEntryAscii(PelTag::GPS_LONGITUDE_REF, $longitude_ref)); $gps_ifd->addEntry(new PelEntryRational(PelTag::GPS_LONGITUDE, $h, $m, $s)); $gps_ifd->addEntry(new PelEntryRational(PelTag::GPS_ALTITUDE, array(0, 0))); $gps_ifd->addEntry(new PelEntryByte(PelTag::GPS_ALTITUDE_REF, 0)); //print($gps_ifd); file_put_contents($input, $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(); }
/** * @param $from_file * @param $to_file */ function copy_exif($from_file, $to_file) { $size = @getimagesize($to_file); if ($size) { require_once dirname(__FILE__) . '/pel/autoload.php'; try { Pel::setJPEGQuality(100); /* * We want the raw JPEG data from $scaled. Luckily, one can create a * PelJpeg object from an image resource directly: */ $input_jpeg = new PelJpeg($from_file); /* Retrieve the original Exif data in $jpeg (if any). */ $input_exif = $input_jpeg->getExif(); /* If no Exif data was present, then $input_exif is null. */ if ($input_exif != null) { $input_tiff = $input_exif->getTiff(); if ($input_tiff == null) { return; } $input_ifd0 = $input_tiff->getIfd(); if ($input_ifd0 == null) { return; } $input_exif_ifd = $input_ifd0->getSubIfd(PelIfd::EXIF); $input_inter_ifd = $input_ifd0->getSubIfd(PelIfd::INTEROPERABILITY); $orientation = $input_ifd0->getEntry(PelTag::ORIENTATION); if ($orientation != null) { $orientation->setValue(1); } if (!empty($input_ifd0)) { /*$x_resolution = $input_ifd0->getEntry( PelTag::X_RESOLUTION ); $y_resolution = $input_ifd0->getEntry( PelTag::Y_RESOLUTION ); if ( $x_resolution != null && $y_resolution != null ) { //$x_res = $x_resolution->getValue(); //$y_res = $y_resolution->getValue(); $x_resolution->setValue( $y_res ); $y_resolution->setValue( $x_res ); }*/ $image_width = $input_ifd0->getEntry(PelTag::IMAGE_WIDTH); $image_length = $input_ifd0->getEntry(PelTag::IMAGE_LENGTH); if ($image_width != null && $image_length != null) { $image_width->setValue($size[0]); $image_length->setValue($size[1]); } } if (!empty($input_exif_ifd)) { $x_dimention = $input_exif_ifd->getEntry(PelTag::PIXEL_X_DIMENSION); $y_dimention = $input_exif_ifd->getEntry(PelTag::PIXEL_Y_DIMENSION); if ($x_dimention != null && $y_dimention != null) { $x_dimention->setValue($size[0]); $y_dimention->setValue($size[1]); } } if (!empty($input_inter_ifd)) { $rel_image_width = $input_inter_ifd->getEntry(PelTag::RELATED_IMAGE_WIDTH); $rel_image_length = $input_inter_ifd->getEntry(PelTag::RELATED_IMAGE_LENGTH); if ($rel_image_width != null && $rel_image_length != null) { $rel_image_width->setValue($size[0]); $rel_image_length->setValue($size[1]); } } $output_jpeg = new PelJpeg($to_file); $output_jpeg->setExif($input_exif); /* We can now save the image with input_exif. */ $output_jpeg->saveFile($to_file); } } catch (PelException $e) { } } }
public function proceedList($zoom, $zoomTmp) { $pic_list_array = $zoom['config']['pic_list_array']; $pic_list_data = $zoom['config']['pic_list_data']; $picSave = $zoom['config']['pic']; if (!$zoom['config']['imgFileOpt']) { $zoom['config']['imgFileOpt'] = array(); } if (!empty($pic_list_array) && !empty($pic_list_data)) { settype($_GET['zoomID'], 'int'); reset($pic_list_array); if (isset($_GET['zoomFile'])) { if (in_array($_GET['zoomFile'], $pic_list_array)) { $flipedArray = array_flip($pic_list_array); $_GET['zoomID'] = $flipedArray[$_GET['zoomFile']]; } } if (!$_GET['zoomID'] or !array_key_exists($_GET['zoomID'], $pic_list_array)) { $_GET['zoomID'] = key($pic_list_array); $zoom['config']['pZoomID'] = false; } else { $zoom['config']['pZoomID'] = $_GET['zoomID']; } if (isset($pic_list_data[$_GET['zoomID']]['path'])) { $startTime = microtime(true); $zoom['config']['picDir'] = $this->checkSlash($zoom['config']['fpPP'] . $this->checkSlash($zoom['config']['pic'] . '/' . $pic_list_data[$_GET['zoomID']]['path'], 'add'), 'add'); if (!is_dir($zoom['config']['picDir'])) { $zoom['config']['picDir'] = $this->checkSlash($zoom['config']['fpPP'] . $this->checkSlash('/' . $pic_list_data[$_GET['zoomID']]['path'], 'add'), 'add'); if (is_dir($zoom['config']['picDir'])) { $zoom['config']['pic'] = ''; } else { $zoom['config']['picDir'] = $this->checkSlash($zoom['config']['fpPP'] . $this->checkSlash($zoom['config']['installPath'] . '/' . $pic_list_data[$_GET['zoomID']]['path'], 'add'), 'add'); if (is_dir($zoom['config']['picDir'])) { $zoom['config']['pic'] = $zoom['config']['installPath']; } } } $this->readTime['findPathFirstImage1'] = $this->endTimeDiff($startTime); } if (!isset($_GET['zoomData']) && !file_exists($zoom['config']['picDir'] . $pic_list_array[$_GET['zoomID']])) { unset($_GET['zoomID']); $pic_list_temp_array = $pic_list_array; $zoomTmp['errorImages'] = array(); $startTime = microtime(true); foreach ($pic_list_array as $k => $v) { if (isset($pic_list_data[$k]['path'])) { $zoom['config']['picDir'] = $this->checkSlash($zoom['config']['fpPP'] . $this->checkSlash($zoom['config']['pic'] . '/' . $pic_list_data[$k]['path'], 'add'), 'add'); } if (file_exists($zoom['config']['picDir'] . $pic_list_array[$k])) { if (!$zoomTmp['picFound']) { $_GET['zoomID'] = $k; $zoomTmp['picFound'] = $k; } } else { $zoomTmp['errorImages'][$k] = $zoom['config']['picDir'] . $pic_list_array[$k]; unset($pic_list_temp_array[$k]); unset($pic_list_data[$k]); } } $this->readTime['findPathFirstImage2'] = $this->endTimeDiff($startTime); if ($zoom['config']['errors'] && !empty($zoomTmp['errorImages'])) { $zoomTmp['fileErrorTitle'] = "Error images missing"; foreach ($zoomTmp['errorImages'] as $k => $v) { $zoomTmp['fileErrorText'] .= "<li>{$v}</li> "; } $zoomTmp['fileErrorText'] = "<ul>" . $zoomTmp['fileErrorText'] . "</ul>"; $this->fileErrorDialog = "<script type=\"text/javascript\">jQuery.fn.axZm.zoomAlert('" . $zoomTmp['fileErrorText'] . "','" . $zoomTmp['fileErrorTitle'] . "',false);</script>"; } $pic_list_array = $pic_list_temp_array; } $zoom['config']['pic_list_array'] = $pic_list_array; $zoom['config']['pic_list_data'] = $pic_list_data; if ($zoom['config']['exifAutoRotation'] && !isset($_GET['str']) && !isset($_GET['qq']) && !isset($_GET['setHW']) && !defined('PHALANGER')) { $pelLib = false; if (file_exists(dirname(__FILE__) . '/classes/pel/PelJpeg.php')) { $pelLib = true; require_once dirname(__FILE__) . '/classes/pel/PelDataWindow.php'; require_once dirname(__FILE__) . '/classes/pel/PelJpeg.php'; require_once dirname(__FILE__) . '/classes/pel/PelTiff.php'; } $startTime = microtime(true); foreach ($pic_list_array as $k => $v) { if (strtolower($this->getl('.', $v)) == 'jpg' || strtolower($this->getl('.', $v)) == 'jpeg') { if (isset($pic_list_data[$k]['path'])) { $tempPicDir = $this->checkSlash($zoom['config']['fpPP'] . $this->checkSlash($zoom['config']['pic'] . '/' . $pic_list_data[$k]['path'], 'add'), 'add'); } else { $tempPicDir = $zoom['config']['picDir']; } $aryEXIF = array(); $aryEXIF = exif_read_data($tempPicDir . $v); if (isset($aryEXIF["Orientation"]) && ($aryEXIF["Orientation"] == 6 || $aryEXIF["Orientation"] == 8 || $aryEXIF["Orientation"] == 3)) { $angle = 0; if ($aryEXIF["Orientation"] == 6) { $angle = 270; } elseif ($aryEXIF["Orientation"] == 8) { $angle = 90; } elseif ($aryEXIF["Orientation"] == 3) { $angle = 180; } if ($angle != 0) { if (is_writable($tempPicDir . $v)) { $this->removeAxZm($zoom, $v, array('In' => true, 'Th' => true, 'tC' => true, 'mO' => true, 'Ti' => true, 'gP' => true), false); if ($pelLib) { $sourceExifFile = new PelJpeg($tempPicDir . $v); $sourceExifInfo = $sourceExifFile->getExif(); } if ($zoom['config']['im']) { $arrAngle = array('270' => '90', '90' => '-90', '180' => '180'); $convertString = $this->whichConvert($zoom['config']['imPath']) . " '" . $tempPicDir . $v . "' -rotate '" . $arrAngle[$angle] . "' '" . $tempPicDir . $v . "'"; $convertString = $this->imQuotes($zoom, $convertString); exec($convertString); } else { $rotatedImage = $this->rotateImage($tempPicDir . $v, $angle); imagejpeg($rotatedImage, $tempPicDir . $v, 100); } if ($pelLib) { $outputExifFile = new PelJpeg($tempPicDir . $v); if ($sourceExifInfo != null) { $outputExifFile->setExif($sourceExifInfo); file_put_contents($tempPicDir . $v, $outputExifFile->getBytes()); } $this->exifOrientation($tempPicDir . $v, $tempPicDir . $v); } $pic_list_data[$k]['imgSize'] = $this->axZm->imageSize($tempPicDir . $v, $zoom['config']['im'], false); } else { if ($zoom['config']['errors']) { echo 'alert("' . $tempPicDir . $v . ' is not writable by PHP.");'; } } } } } $zoom['config']['pic_list_data'] = $pic_list_data; } $this->readTime['exifAutoRotation'] = $this->endTimeDiff($startTime); } if ($zoom['config']['cTimeCompare'] && !isset($_GET['setHW']) && !isset($_GET['str']) && !isset($_GET['qq'])) { $this->cTimeCompare($zoom); } if (isset($_GET['zoomID']) && !isset($_GET['qq'])) { if (isset($pic_list_data[$_GET['zoomID']]['path'])) { $zoom['config']['picDir'] = $this->checkSlash($zoom['config']['fpPP'] . $this->checkSlash($zoom['config']['pic'] . '/' . $pic_list_data[$_GET['zoomID']]['path'], 'add'), 'add'); } $zoom['config']['orgImgName'] = $pic_list_array[$_GET['zoomID']]; if ($pic_list_data[$_GET['zoomID']]['imgSize']) { $zoom['config']['orgImgSize'] = $pic_list_data[$_GET['zoomID']]['imgSize']; } else { $zoom['config']['orgImgSize'] = $this->axZm->imageSize($zoom['config']['picDir'] . $zoom['config']['orgImgName'], $zoom['config']['im'], false); } $zoom['config']['smallImgName'] = $this->composeFileName($pic_list_array[$_GET['zoomID']], $zoom['config']['picDim'], '_', $this->pngMod($zoom)); $imageSlicer = $zoom['config']['imageSlicer']; if (!is_array($imageSlicer)) { $imageSlicer = array(); } $slicerPostArr = array('zoomID' => $_GET['zoomID'], 'example' => $_GET['example'], 'pic' => $zoom['config']['pic'], 'pic_list_data' => serialize(array($_GET['zoomID'] => $pic_list_data[$_GET['zoomID']])), 'pic_list_array' => serialize(array($_GET['zoomID'] => $pic_list_array[$_GET['zoomID']]))); if ($imageSlicer['enabled'] && !empty($imageSlicer['parameters'])) { foreach ($imageSlicer['parameters'] as $a => $b) { if (isset($_GET[$b])) { $slicerPostArr[$b] = $_GET[$b]; } } } $checkInitialImage = true; if (!$zoom['config']['imgFileOpt']['noMakeFirstImage']) { if ($zoom['config']['stepPicDim'] && is_array($zoom['config']['stepPicDim']) && !empty($zoom['config']['stepPicDim'])) { foreach ($zoom['config']['stepPicDim'] as $k => $v) { if ((int) $v['w'] && (int) $v['h'] && !file_exists($zoom['config']['thumbDir'] . $this->md5path($zoom['config']['orgImgName'], $zoom['config']['subfolderStructure']) . '/' . $this->composeFileName($zoom['config']['orgImgName'], (int) $v['w'] . 'x' . (int) $v['h'], '_', $this->pngMod($zoom)))) { $checkInitialImage = false; break; } } } else { $checkInitialImage = file_exists($zoom['config']['thumbDir'] . $this->md5path($zoom['config']['orgImgName'], $zoom['config']['subfolderStructure']) . $zoom['config']['smallImgName']); } } if (!$checkInitialImage) { if ($imageSlicer['enabled']) { $slicerPostArr['task'] = 'makeFirstImage'; $this->returnMakeFirstImage = $this->httpRequestQuery($imageSlicer['method'], $imageSlicer['host'], $imageSlicer['port'], $imageSlicer['uri'], $imageSlicer['timeout'], $imageSlicer['method'] == 'GET' ? $slicerPostArr : array(), $imageSlicer['method'] == 'POST' ? $slicerPostArr : array(), $imageSlicer['headers']); } else { $startTime = microtime(true); $this->returnMakeFirstImage = $this->axZm->makeFirstImage($zoom, false); $this->readTime['makeFirstImage1'] = $this->endTimeDiff($startTime); } } elseif ($zoom['config']['mapOwnImage'] && !$zoom['config']['imgFileOpt']['noMakeMapImage']) { if (!isset($zoom['config']['mapDir'])) { $zoom['config']['mapDir'] = $this->checkSlash($zoom['config']['fpPP'] . $zoom['config']['mapPath'], 'add'); } if (!file_exists($zoom['config']['mapDir'] . $this->composeFileName($zoom['config']['orgImgName'], $zoom['config']['mapOwnImage'], '_', $this->pngMod($zoom)))) { if ($imageSlicer['enabled']) { $slicerPostArr['task'] = 'makeMapImage'; $this->returnMakeFirstImage = $this->httpRequestQuery($imageSlicer['method'], $imageSlicer['host'], $imageSlicer['port'], $imageSlicer['uri'], $imageSlicer['timeout'], $imageSlicer['method'] == 'GET' ? $slicerPostArr : array(), $imageSlicer['method'] == 'POST' ? $slicerPostArr : array(), $imageSlicer['headers']); } else { $startTime = microtime(true); $this->returnMakeFirstImage = $this->axZm->makeFirstImage($zoom, true); $this->readTime['makeFirstImage2'] = $this->endTimeDiff($startTime); } } } $startTime = microtime(true); if ($zoom['config']['imgFileOpt']['noMakeFirstImage']) { $zoom['config']['smallImgSize'] = $this->virtualResize($pic_list_data[$_GET['zoomID']]['imgSize'], array($zoom['config']['picX'], $zoom['config']['picY'])); } else { $zoom['config']['smallImgSize'] = $this->axZm->imageSize($zoom['config']['thumbDir'] . $this->md5path($zoom['config']['orgImgName'], $zoom['config']['subfolderStructure']) . $zoom['config']['smallImgName'], $zoom['config']['im'], false); } $this->readTime['smallImgSizeDim'] = $this->endTimeDiff($startTime); if ($zoom['config']['imgFileOpt']['getFileSize']) { $startTime = microtime(true); $zoom['config']['smallFileSize'] = filesize($zoom['config']['thumbDir'] . $this->md5path($zoom['config']['orgImgName'], $zoom['config']['subfolderStructure']) . $zoom['config']['smallImgName']); $this->readTime['smallImgFileSize'] = $this->endTimeDiff($startTime); } if (isset($_GET['setHW'])) { echo "<script type=\"text/javascript\">"; echo "\r\n\t\t\t\t\tjQuery.axZm.iw=" . $this->ptj($zoom['config']['smallImgSize'][0]) . ";\r\n\t\t\t\t\tjQuery.axZm.ih=" . $this->ptj($zoom['config']['smallImgSize'][1]) . ";\r\n\t\t\t\t\t"; echo "</script>\r\n\t\t\t\t\t"; if (!is_bool($this->returnMakeFirstImage)) { echo $this->returnMakeFirstImage; } } if (!isset($_GET['str'])) { if (!isset($_GET['setHW'])) { $firstThumbSize = null; $startTime = microtime(true); foreach ($pic_list_array as $k => $v) { $zoomTmp['smallImgNameTemp'] = $this->composeFileName($v, $zoom['config']['picDim'], '_', $this->pngMod($zoom)); if ($zoom['config']['imgFileOpt']['noMakeFirstImage']) { $pic_list_data[$k]['thumbSize'] = $this->virtualResize($pic_list_data[$k]['imgSize'], array($zoom['config']['picX'], $zoom['config']['picY'])); } else { if (file_exists($zoom['config']['thumbDir'] . $this->md5path($v, $zoom['config']['subfolderStructure']) . $zoomTmp['smallImgNameTemp'])) { if ($firstThumbSize && ($zoom['config']['imgFileOpt']['sameAspectRatio'] || $zoom['config']['imgFileOpt']['sameSize'] || $zoom['config']['spinMod'])) { $pic_list_data[$k]['thumbSize'] = $firstThumbSize; } else { $pic_list_data[$k]['thumbSize'] = $this->axZm->imageSize($zoom['config']['thumbDir'] . $this->md5path($v, $zoom['config']['subfolderStructure']) . $zoomTmp['smallImgNameTemp'], $zoom['config']['im'], false); } if (!$firstThumbSize) { $firstThumbSize = $pic_list_data[$k]['thumbSize']; } } else { $pic_list_data[$k]['thumbSize'] = false; } } } $this->readTime['smallImgSizeDimAll'] = $this->endTimeDiff($startTime); $zoom['config']['pic_list_data'] = $pic_list_data; if ((!isset($zoom['config']['galleryNoThumbs']) || $zoom['config']['galleryNoThumbs'] === false) && !$zoom['config']['imgFileOpt']['noMakeAllThumbs']) { if ($imageSlicer['enabled']) { $slicerPostThumbsArr = array('task' => 'makeAllThumbs', 'zoomID' => $_GET['zoomID'], 'example' => $_GET['example'], 'pic' => $zoom['config']['pic'], 'pic_list_data' => serialize($pic_list_data), 'pic_list_array' => serialize($pic_list_array)); if (!empty($imageSlicer['parameters'])) { foreach ($imageSlicer['parameters'] as $a => $b) { if (isset($_GET[$b])) { $slicerPostThumbsArr[$b] = $_GET[$b]; } } } $this->returnMakeAllThumbs = $this->httpRequestQuery($imageSlicer['method'], $imageSlicer['host'], $imageSlicer['port'], $imageSlicer['uri'], $imageSlicer['timeout'], $imageSlicer['method'] == 'GET' ? $slicerPostThumbsArr : array(), $imageSlicer['method'] == 'POST' ? $slicerPostThumbsArr : array(), $imageSlicer['headers']); } else { $startTime = microtime(true); $this->returnMakeAllThumbs = $this->axZm->makeAllThumbs($zoom); $this->readTime['makeAllThumbs'] = $this->endTimeDiff($startTime); } } else { $this->returnMakeAllThumbs = false; } } if ($zoom['config']['gPyramid'] && $zoom['config']['gPyramidDir']) { $startTime = microtime(true); if (!$zoom['config']['imgFileOpt']['noMakeGpyramid']) { $zoomTmp['gPyramidPicDir'] = $zoom['config']['gPyramidDir'] . $this->md5path($zoom['config']['orgImgName'], $zoom['config']['subfolderStructure']) . $this->getf('.', $zoom['config']['orgImgName']); $zoomTmp['gPyramidPicDirExists'] = is_dir($zoomTmp['gPyramidPicDir']); if (!$zoomTmp['gPyramidPicDirExists']) { if ($imageSlicer['enabled']) { $slicerPostArr['task'] = 'gPyramid'; $this->returnMakeZoomTiles = $this->httpRequestQuery($imageSlicer['method'], $imageSlicer['host'], $imageSlicer['port'], $imageSlicer['uri'], $imageSlicer['timeout'], $imageSlicer['method'] == 'GET' ? $slicerPostArr : array(), $imageSlicer['method'] == 'POST' ? $slicerPostArr : array(), $imageSlicer['headers']); } else { $this->returnMakeZoomTiles = $this->axZm->gPyramid($zoom); } if (isset($_GET['setHW']) && !is_bool($this->returnMakeZoomTiles)) { echo $this->returnMakeZoomTiles; } } } $this->readTime['gPyramid'] = $this->endTimeDiff($startTime); } if ($zoom['config']['pyrTiles'] && $zoom['config']['pyrTilesDir']) { $startTime = microtime(true); if (!$zoom['config']['imgFileOpt']['noMakeZoomTiles'] && ($zoom['config']['orgImgSize'][0] >= $zoom['config']['tileSize'] || $zoom['config']['orgImgSize'][1] >= $zoom['config']['tileSize'])) { $this->returnMakeZoomTiles = $this->axZm->zC($zoom, false); if (!$zoom['config']['imgFileOpt']['noMakeZoomTiles'] && !$this->tileExists($zoom, $zoom['config']['orgImgName'])) { if ($imageSlicer['enabled']) { $slicerPostArr['task'] = 'makeZoomTiles'; $this->returnMakeZoomTiles = $this->httpRequestQuery($imageSlicer['method'], $imageSlicer['host'], $imageSlicer['port'], $imageSlicer['uri'], $imageSlicer['timeout'], $imageSlicer['method'] == 'GET' ? $slicerPostArr : array(), $imageSlicer['method'] == 'POST' ? $slicerPostArr : array(), $imageSlicer['headers']); } else { $this->returnMakeZoomTiles = $this->axZm->makeZoomTiles($zoom); } } if (isset($_GET['setHW']) && !is_bool($this->returnMakeZoomTiles) && $this->returnMakeZoomTiles) { echo $this->returnMakeZoomTiles; } } $this->readTime['makeZoomTiles'] = $this->endTimeDiff($startTime); } if (!isset($_GET['setHW'])) { $startTime = microtime(true); foreach ($pic_list_data as $k => $v) { $zoom['config']['galArray'][$k]['img'] = $v['fileName']; $zoom['config']['galArray'][$k]['ow'] = $v['imgSize'][0]; $zoom['config']['galArray'][$k]['oh'] = $v['imgSize'][1]; $zoom['config']['galArray'][$k]['iw'] = $v['thumbSize'][0]; $zoom['config']['galArray'][$k]['ih'] = $v['thumbSize'][1]; $zoom['config']['galArray'][$k]['tD'] = $v['thumbDescr']; $zoom['config']['galArray'][$k]['fD'] = $v['fullDescr']; $zoom['config']['galArray'][$k]['mf'] = false; $zoom['config']['galArray'][$k]['mk'] = false; if ($zoom['config']['useMap'] && !$zoom['config']['imgFileOpt']['noMakeMapImage'] && $zoom['config']['mapOwnImage'] && $zoom['config']['mapDir']) { $ownImageSize = explode('x', $zoom['config']['mapOwnImage']); $ownImageName = $this->composeFileName($v['fileName'], $ownImageSize[0] . 'x' . $ownImageSize[1], '_', $this->pngMod($zoom)); if (!file_exists($zoom['config']['mapDir'] . $this->md5path($v['fileName'], $zoom['config']['subfolderStructure']) . $ownImageName)) { $zoom['config']['galArray'][$k]['mf'] = true; } } if ($zoom['config']['stepPicDim'] && !$zoom['config']['imgFileOpt']['noMakeFirstImage'] && is_array($zoom['config']['stepPicDim']) && !empty($zoom['config']['stepPicDim'])) { foreach ($zoom['config']['stepPicDim'] as $a => $b) { if ((int) $b['w'] && (int) $b['h'] && !file_exists($zoom['config']['thumbDir'] . $this->md5path($v['fileName'], $zoom['config']['subfolderStructure']) . $this->composeFileName($v['fileName'], (int) $b['w'] . 'x' . (int) $b['h'], '_', $this->pngMod($zoom)))) { $zoom['config']['galArray'][$k]['mf'] = true; break; } } } if (isset($v['path'])) { $zoom['config']['galArray'][$k]['ph'] = $this->checkSlash($v['picPath'], 'add'); } if ($zoom['config']['gPyramid'] && !$zoom['config']['imgFileOpt']['noMakeGpyramid']) { if (is_dir($zoom['config']['gPyramidDir'] . $this->md5path($v['fileName'], $zoom['config']['subfolderStructure']) . $this->getf('.', $v['fileName']))) { $zoom['config']['galArray'][$k]['mk'] = false; } else { $zoom['config']['galArray'][$k]['mk'] = 'gP'; } } elseif ($zoom['config']['pyrTiles'] && !$zoom['config']['imgFileOpt']['noMakeZoomTiles']) { if ($v['imgSize'][0] < $zoom['config']['tileSize'] && $v['imgSize'][1] < $zoom['config']['tileSize'] || $this->tileExists($zoom, $v['fileName'])) { $zoom['config']['galArray'][$k]['mk'] = false; if ($zoom['config']['pyrAutoDetect']) { $zoom['config']['galArray'][$k]['ts'] = $this->getTileSize($zoom, $v['fileName']); } } else { $zoom['config']['galArray'][$k]['mk'] = 'tL'; } } } $this->readTime['galleryData'] = $this->endTimeDiff($startTime); } } if (isset($pic_list_data[$_GET['zoomID']]['path'])) { $zoom['config']['pic'] = $this->checkSlash($zoom['config']['pic'] . '/' . $pic_list_data[$_GET['zoomID']]['path'], 'add'); } } } else { unset($_GET['zoomID']); } $this->readTime['pyrAutoDetect'] = $zoom['config']['pyrAutoDetect']; $this->readTime['imgFileOpt'] = $zoom['config']['imgFileOpt']; return array($zoom, $zoomTmp); }
function addExif($filename, $exifdata) { try { $jpeg = new PelJpeg($filename); if (!($exif = $jpeg->getExif())) { // Create and add empty Exif data to the image (this throws away any old Exif data in the image). $exif = new PelExif(); $jpeg->setExif($exif); } if (!($tiff = $exif->getTiff())) { // Create and add TIFF data to the Exif data (Exif data is actually stored in a TIFF format). $tiff = new PelTiff(); $exif->setTiff($tiff); } if (!($ifd0 = $tiff->getIfd())) { // Create first Image File Directory and associate it with the TIFF data. $ifd0 = new PelIfd(PelIfd::IFD0); $tiff->setIfd($ifd0); } if (!($exif_ifd = $ifd0->getSubIfd(PelIfd::EXIF))) { // Create first Image File Directory and associate it with the TIFF data. $exif_ifd = new PelIfd(PelIfd::EXIF); $ifd0->addSubIfd($exif_ifd); } if (!($ifd1 = $ifd0->getNextIfd())) { // thumbnail does not exist $ifd1 = new PelIfd(1); $ifd0->setNextIfd($ifd1); $original = ImageCreateFromString($jpeg->getBytes()); # create image resource of original $thumb = makeThumb($original); // start writing output to buffer ob_start(); // outputs thumb resource contents to buffer ImageJpeg($thumb); // create PelDataWindow from buffer thumb contents (and end output to buffer) $window = new PelDataWindow(ob_get_clean()); if ($window) { $ifd1->setThumbnail($window); # set window data as thumbnail in ifd1 } imagedestroy($original); imagedestroy($thumb); } foreach ($exifdata as $PelTag => $val) { if ($PelTag == PelTag::USER_COMMENT) { if (!($entry = $exif_ifd->getEntry($PelTag))) { $exif_ifd->addEntry(new PelEntryUserComment($val)); } else { $entry->setValue($val); } } else { if (!($entry = $ifd0->getEntry($PelTag))) { $ifd0->addEntry(new PelEntryAscii($PelTag, $val)); } else { $entry->setValue($val); } } } $jpeg->saveFile($filename); return true; } catch (Exception $e) { // Handle exception echo $e; } }
/** * This method calculates the image and delivers it to the client. * * @param $folder * @param $file * @param $width * @param $height * @param $mode */ public function resize($folder, $file, $width = -1, $height = -1, $mode = 'nocrop') { $jpeg_orientation_translation = array(1 => 0, 2 => 0, 3 => 180, 4 => 0, 5 => 0, 6 => -90, 7 => 0, 8 => 90); /** * @var JApplicationSite $app */ $app = JFactory::getApplication(); $params = $app->getParams(); if (strcmp($mode, 'full') == 0) { $mode = 'nocrop'; $width = COM_EVENTGALLERY_IMAGE_ORIGINAL_MAX_WIDTH; $height = COM_EVENTGALLERY_IMAGE_ORIGINAL_MAX_WIDTH; } if ($height > $width) { $width = $height; } $sizeSet = new EventgalleryHelpersSizeset(); $saveAsSize = $sizeSet->getMatchingSize($width); $file = STR_REPLACE("\\.\\.", "", $file); $folder = STR_REPLACE("\\.\\.", "", $folder); $width = STR_REPLACE("\\.\\.", "", $width); $mode = STR_REPLACE("\\.\\.", "", $mode); $file = STR_REPLACE("/", "", $file); $folder = STR_REPLACE("/", "", $folder); $width = STR_REPLACE("/", "", $width); $mode = STR_REPLACE("/", "", $mode); $file = STR_REPLACE("\\", "", $file); $folder = STR_REPLACE("\\", "", $folder); $width = STR_REPLACE("\\", "", $width); $mode = STR_REPLACE("\\", "", $mode); $basedir = COM_EVENTGALLERY_IMAGE_FOLDER_PATH; $sourcedir = $basedir . $folder; $cachebasedir = COM_EVENTGALLERY_IMAGE_CACHE_PATH; $cachedir = $cachebasedir . $folder; $cachedir_thumbs = $cachebasedir . $folder; if (!is_dir(JPATH_CACHE)) { //mkdir($cachebasedir, 0777); mkdir(JPATH_CACHE); } if (!is_dir($cachebasedir)) { //mkdir($cachebasedir, 0777); mkdir($cachebasedir); } if (!is_dir($cachedir)) { //mkdir($cachedir, 0777); mkdir($cachedir); } if (!is_dir($cachedir_thumbs)) { //mkdir($cachedir_thumbs, 0777); mkdir($cachedir_thumbs); } $image_file = $sourcedir . DIRECTORY_SEPARATOR . $file; $image_thumb_file = $cachedir_thumbs . DIRECTORY_SEPARATOR . $mode . $saveAsSize . $file; //$last_modified = gmdate('D, d M Y H:i:s T', filemtime ($image_file)); $last_modified = gmdate('D, d M Y H:i:s T', mktime(0, 0, 0, 1, 1, 2100)); #echo "<br>".$image_thumb_file."<br>"; $debug = false; if ($debug || !file_exists($image_thumb_file)) { $ext = pathinfo($image_file, PATHINFO_EXTENSION); $input_jpeg = null; $exif = null; if (strtolower($ext) == "gif") { if (!($im_original = imagecreatefromgif($image_file))) { echo "Error opening {$image_file}!"; exit; } } else { if (strtolower($ext) == "jpg" || strtolower($ext) == "jpeg") { // try to use PEL first. If things fail, use the php internal method to get the JPEG try { $input_jpeg = new PelJpeg($image_file); /* Retrieve the original Exif data in $jpeg (if any). */ $exif = $input_jpeg->getExif(); /* The input image is already loaded, so we can reuse the bytes stored * in $input_jpeg when creating the Image resource. */ if (!($im_original = ImageCreateFromString($input_jpeg->getBytes()))) { echo "Error opening {$image_file}!"; exit; } } catch (Exception $e) { if (!($im_original = imagecreatefromjpeg($image_file))) { echo "Error opening {$image_file}!"; exit; } } } else { if (strtolower($ext) == "png") { if (!($im_original = imagecreatefrompng($image_file))) { echo "Error opening {$image_file}!"; exit; } } else { die("{$ext} not supported"); } } } if ($params->get('use_autorotate', 1) == 1 && $exif != NULL) { $tiff = $exif->getTiff(); $ifd0 = $tiff->getIfd(); $orientation = $ifd0->getEntry(PelTag::ORIENTATION); if ($orientation != null) { $im_original = imagerotate($im_original, $jpeg_orientation_translation[$orientation->getValue()], 0); $orientation->setValue(1); } } $orig_width = imagesx($im_original); $orig_height = imagesy($im_original); $orig_ratio = imagesx($im_original) / imagesy($im_original); $sizeCalc = new EventgalleryHelpersSizecalculator($orig_width, $orig_height, $width, strcmp('crop', $mode) == 0); $height = $sizeCalc->getHeight(); $width = $sizeCalc->getWidth(); //print_r($sizeCalc); // create canvas/border image //adjust height to not enlarge images if ($width > $orig_width) { $width = $orig_width; } if ($height > $orig_height) { $height = $orig_height; } if (strcmp('crop', $mode) != 0) { $canvasWidth = $width; $canvasHeight = ceil($width / $orig_ratio); if ($canvasHeight > $height) { $canvasHeight = $height; $canvasWidth = ceil($height * $orig_ratio); } $width = $canvasWidth; $height = $canvasHeight; } else { $height = $width; } $isOriginalSize = false; if ($height == $orig_height && $width == $orig_width) { $isOriginalSize = true; } /** * Do not recalculate the image if we don't need to resize it. */ if ($isOriginalSize && $params->get('use_sharpening_for_originalsize', 1) == 0) { $im_output = $im_original; } else { $im_output = imagecreatetruecolor($width, $height); $resize_faktor = $orig_height / $height; $new_height = $height; $new_width = $orig_width / $resize_faktor; if ($new_width < $width) { $resize_faktor = $orig_width / $width; $new_width = $width; $new_height = $orig_height / $resize_faktor; } imagecopyresampled($im_output, $im_original, $width / 2 - $new_width / 2, $height / 2 - $new_height / 2, 0, 0, $new_width, $new_height, $orig_width, $orig_height); $use_sharpening = $params->get('use_sharpening', 1); if ($use_sharpening == 1) { // configure the sharpening $stringSharpenMatrix = $params->get('image_sharpenMatrix', '[[-1,-1,-1],[-1,16,-1],[-1,-1,-1]]'); $sharpenMatrix = json_decode($stringSharpenMatrix); if (null == $sharpenMatrix || count($sharpenMatrix) != 3) { $sharpenMatrix = array(array(-1, -1, -1), array(-1, 16, -1), array(-1, -1, -1)); } $divisor = array_sum(array_map('array_sum', $sharpenMatrix)); $offset = 0; if (function_exists('imageconvolution')) { if (version_compare(phpversion(), '5.5.9', '=')) { $this->imageconvolution($im_output, $sharpenMatrix, $divisor, $offset); } else { imageconvolution($im_output, $sharpenMatrix, $divisor, $offset); } } } } /** * @var EventgalleryLibraryManagerFolder $folderMgr * @var EventgalleryLibraryFolder $folder */ $folderMgr = EventgalleryLibraryManagerFolder::getInstance(); $folder = $folderMgr->getFolder($folder); $watermark = $folder->getWatermark(); // load default watermark if (null == $watermark || !$watermark->isPublished()) { /** * @var EventgalleryLibraryManagerWatermark $watermarkMgr * @var EventgalleryLibraryWatermark $watermark */ $watermarkMgr = EventgalleryLibraryManagerWatermark::getInstance(); $watermark = $watermarkMgr->getDefaultWatermark(); } if (null != $watermark && $watermark->isPublished()) { $watermark->addWatermark($im_output); } $image_quality = $params->get('image_quality', 85); if ($input_jpeg != null) { Pel::setJPEGQuality($image_quality); /* We want the raw JPEG data from $scaled. Luckily, one can create a * PelJpeg object from an image resource directly: */ $output_jpeg = new PelJpeg($im_output); /* If no Exif data was present, then $exif is null. */ if ($exif != null) { $output_jpeg->setExif($exif); } /* We can now save the scaled image. */ $writeSuccess = true; $output_jpeg->saveFile($image_thumb_file); } else { $writeSuccess = imagejpeg($im_output, $image_thumb_file, $image_quality); if (!$writeSuccess) { die("Unable to write to file {$image_thumb_file}"); } } if (!$writeSuccess) { die("Unable to write to file {$image_thumb_file}"); } $time = time() + 315360000; touch($image_thumb_file, $time); // add the ICC profile try { $o = new JPEG_ICC(); $o->LoadFromJPEG($image_file); $o->SaveToJPEG($image_thumb_file); } catch (Exception $e) { } } $mime = ($mime = getimagesize($image_thumb_file)) ? $mime['mime'] : $mime; $size = filesize($image_thumb_file); $fp = fopen($image_thumb_file, "rb"); if (!($mime && $size && $fp)) { // Error. return; } if (!$debug) { header("Content-Type: " . $mime); header("Content-Length: " . $size); header("Last-Modified: {$last_modified}"); } fpassthru($fp); die; //$app->close(); }
/** * Check the existance of the files and generate everything needed on the fly * @access public * @param array $zoom * @param array $zoomTmp * @return array $zoom, $zoomTmp **/ public function proceedList($zoom, $zoomTmp) { if ($zoom['config']['cTimeCompare']) { $this->cTimeCompare($zoom); } $pic_list_array = $zoom['config']['pic_list_array']; $pic_list_data = $zoom['config']['pic_list_data']; if (!empty($pic_list_array) and !empty($pic_list_data)) { ////////////////////////////////////////////////////////////////////////////////////////////////////// //// Select the first picture if no zoomID /////////////////////////////////////////////////////////// //// passed over query string //////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////// // zoomID must be a number (integer) > 0 !!! settype($_GET['zoomID'], 'int'); // Set the internal pointer of an array to its first element reset($pic_list_array); // You can also pass the filename, which has to exist in the $pic_list_array if (isset($_GET['zoomFile'])) { if (in_array($_GET['zoomFile'], $pic_list_array)) { $flipedArray = array_flip($pic_list_array); $_GET['zoomID'] = $flipedArray[$_GET['zoomFile']]; } } // If no zoomID passed or zoomID is not a key in picture array if (!$_GET['zoomID'] or !array_key_exists($_GET['zoomID'], $pic_list_array)) { // then select the first picture in defined array $_GET['zoomID'] = key($pic_list_array); } // Redefine the root path of the image if (isset($pic_list_data[$_GET['zoomID']]['path'])) { $zoom['config']['picDir'] = $this->checkSlash($zoom['config']['fpPP'] . $this->checkSlash($zoom['config']['pic'] . '/' . $pic_list_data[$_GET['zoomID']]['path'], 'add'), 'add'); // Heuristic approach if (!is_dir($zoom['config']['picDir'])) { $zoom['config']['picDir'] = $this->checkSlash($zoom['config']['fpPP'] . $this->checkSlash('/' . $pic_list_data[$_GET['zoomID']]['path'], 'add'), 'add'); if (is_dir($zoom['config']['picDir'])) { $zoom['config']['pic'] = ''; } else { $zoom['config']['picDir'] = $this->checkSlash($zoom['config']['fpPP'] . $this->checkSlash($zoom['config']['installPath'] . '/' . $pic_list_data[$_GET['zoomID']]['path'], 'add'), 'add'); if (is_dir($zoom['config']['picDir'])) { $zoom['config']['pic'] = $zoom['config']['installPath']; } } } } //////////////////////////////////////////////////////////////////////////////////////////////////////// //// Check if source file exists /////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////// // If for some reason there the original image does not exist, there is a problem, which could be solved // This may happen if you get images from the database entry, // but they do not exist in the filesystem because you may intentionally or unintentionally renamed them or whatever... // So we need to check the whole array if such an error occures if (!file_exists($zoom['config']['picDir'] . $pic_list_array[$_GET['zoomID']])) { // The passed zoomID is problematic! Unset it. unset($_GET['zoomID']); $pic_list_temp_array = $pic_list_array; $zoomTmp['errorImages'] = array(); // Loop through the $pic_list_array to find a picture that exists foreach ($pic_list_array as $k => $v) { if (isset($pic_list_data[$k]['path'])) { $zoom['config']['picDir'] = $this->checkSlash($zoom['config']['fpPP'] . $this->checkSlash($zoom['config']['pic'] . '/' . $pic_list_data[$k]['path'], 'add'), 'add'); } // If we have found an image, that exists :-) if (file_exists($zoom['config']['picDir'] . $pic_list_array[$v])) { // If we have not found an existing picture already if (!$zoomTmp['picFound']) { // Define $_GET['zoomID'] with the image key from $pic_list_array $_GET['zoomID'] = $k; // Define a var that tells the loop about a successful finding $zoomTmp['picFound'] = $k; } } else { $zoomTmp['errorImages'][$k] = $zoom['config']['picDir'] . $pic_list_array[$k]; //Patch: 20101-01-01 ($pic_list_array[$k] not $pic_list_array[$v]) // Remove this picture from the arrays unset($pic_list_temp_array[$k]); unset($pic_list_data[$k]); } } // If you have defined in zoomConfig.inc.php to show errors if ($zoom['config']['errors'] && !empty($zoomTmp['errorImages'])) { // Trigger message that lists missing images (with method drawZoomBox of axZmH.class.php) $zoomTmp['fileErrorTitle'] = "Error images missing"; // Display also the paths of images that can not be found foreach ($zoomTmp['errorImages'] as $k => $v) { $zoomTmp['fileErrorText'] .= "<li>{$v}</li> "; } // Compute what has been removed (not needed) /* $zoomTmp['fileError'] = array_diff($pic_list_array, $pic_list_temp_array); foreach ($zoomTmp['fileError'] as $k=>$v){$zoomTmp['fileErrorText'].="<li>$v</li> ";} */ $zoomTmp['fileErrorText'] = "<ul>" . $zoomTmp['fileErrorText'] . "</ul>"; $this->fileErrorDialog = "<script type=\"text/javascript\">jQuery.fn.axZm.zoomAlert('" . $zoomTmp['fileErrorText'] . "','" . $zoomTmp['fileErrorTitle'] . "',false);</script>"; } // Redefine the basic $pic_list_array with removed items $pic_list_array = $pic_list_temp_array; } // Store information in $zoom['config'] $zoom['config']['pic_list_array'] = $pic_list_array; $zoom['config']['pic_list_data'] = $pic_list_data; // Exif orientation if ($zoom['config']['exifAutoRotation'] && !isset($_GET['str']) && !isset($_GET['setHW']) && !defined('PHALANGER')) { $pelLib = false; // http://lsolesen.github.com/pel/ if (file_exists(dirname(__FILE__) . '/classes/pel/PelJpeg.php')) { $pelLib = true; require_once dirname(__FILE__) . '/classes/pel/PelDataWindow.php'; require_once dirname(__FILE__) . '/classes/pel/PelJpeg.php'; require_once dirname(__FILE__) . '/classes/pel/PelTiff.php'; } foreach ($pic_list_array as $k => $v) { if (strtolower($this->getl('.', $v)) == 'jpg' || strtolower($this->getl('.', $v)) == 'jpeg') { if (isset($pic_list_data[$k]['path'])) { $tempPicDir = $this->checkSlash($zoom['config']['fpPP'] . $this->checkSlash($zoom['config']['pic'] . '/' . $pic_list_data[$k]['path'], 'add'), 'add'); } else { $tempPicDir = $zoom['config']['picDir']; } $aryEXIF = array(); $aryEXIF = exif_read_data($tempPicDir . $v); if (isset($aryEXIF["Orientation"]) && ($aryEXIF["Orientation"] == 6 || $aryEXIF["Orientation"] == 8)) { $angle = 0; if ($aryEXIF["Orientation"] == 6) { $angle = 270; } elseif ($aryEXIF["Orientation"] == 8) { $angle = 90; } if ($angle != 0) { if (is_writable($tempPicDir . $v)) { // Delete all already made tiles, thumbs etc. $this->removeAxZm($zoom, $v, array('In' => true, 'Th' => true, 'Ti' => true, 'gP' => true), false); // Save exif info if ($pelLib) { $sourceExifFile = new PelJpeg($tempPicDir . $v); $sourceExifInfo = $sourceExifFile->getExif(); } // Rotate $rotatedImage = $this->rotateImage($tempPicDir . $v, $angle); imagejpeg($rotatedImage, $tempPicDir . $v, 100); // Transfere EXIF information if ($pelLib) { $outputExifFile = new PelJpeg($tempPicDir . $v); if ($sourceExifInfo != null) { $outputExifFile->setExif($sourceExifInfo); file_put_contents($tempPicDir . $v, $outputExifFile->getBytes()); } // Reset the EXIF-tag "orientation" $this->exifOrientation($tempPicDir . $v, $tempPicDir . $v); } $pic_list_data[$k]['imgSize'] = $this->axZm->imageSize($tempPicDir . $v, $zoom['config']['im'], false); } else { if ($zoom['config']['errors']) { echo 'alert("' . $tempPicDir . $v . ' is not writable by PHP.");'; } } } } } $zoom['config']['pic_list_data'] = $pic_list_data; } } // By now we have generated and checked $pic_list_array and $pic_list_data // $_GET['zoomID'] is also checked and should exist if (isset($_GET['zoomID'])) { // Redefine the root path of the image if (isset($pic_list_data[$_GET['zoomID']]['path'])) { $zoom['config']['picDir'] = $this->checkSlash($zoom['config']['fpPP'] . $this->checkSlash($zoom['config']['pic'] . '/' . $pic_list_data[$_GET['zoomID']]['path'], 'add'), 'add'); } //////////////////////////////////////////////////// //// Important for next code and zoomLoad.php !!!/// //////////////////////////////////////////////////// // 1. $zoom['config']['orgImgName'] // filename of the source image // 2. $zoom['config']['orgImgSize'] // imagesize of the source image // 3. $zoom['config']['smallImgName'] // filename of the initial image // 4. $zoom['config']['smallImgSize'] // imagesize of the initial image // 5. $zoom['config']['smallFileSize'] // filesize of thr initial image // 1. Filename of the source image $zoom['config']['orgImgName'] = $pic_list_array[$_GET['zoomID']]; // 2. Imagesize of the source image [array(0=>width, 1=>height)] // Do not replace it with $pic_list_data[$_GET['zoomID']]['imgSize'] // since this information will only be generated on load and we also need it for zooming (zoomLoad.php) $zoom['config']['orgImgSize'] = $this->axZm->imageSize($zoom['config']['picDir'] . $zoom['config']['orgImgName'], $zoom['config']['im'], false); // 3. Filename of the initial image // This image will be loaded first (without zoom) // Before it has to be resized with $zoom['config']['picDim'] and saved in $zoom['config']['thumbDir'] // e.g. imagename is abcdefgh.jpg, $zoom['config']['picDim'] = '600x400'; // It will be then saved as abcdefgh_600x400.jpg in $zoom['config']['thumbDir'] $zoom['config']['smallImgName'] = $this->composeFileName($pic_list_array[$_GET['zoomID']], $zoom['config']['picDim'], '_', $this->pngMod($zoom)); // 4. Make initial image on the fly and save it once // Only current displayed image will be made on the fly // Check if it exists first if (!file_exists($zoom['config']['thumbDir'] . $zoom['config']['smallImgName'])) { // Make first image $this->returnMakeFirstImage = $this->axZm->makeFirstImage($zoom, false); } else { if ($zoom['config']['mapOwnImage']) { if (!isset($zoom['config']['mapDir'])) { $zoom['config']['mapDir'] = $axZmH->checkSlash($zoom['config']['fpPP'] . $zoom['config']['mapPath'], 'add'); } if (!file_exists($zoom['config']['mapDir'] . $this->composeFileName($zoom['config']['orgImgName'], $zoom['config']['mapOwnImage'], '_', $this->pngMod($zoom)))) { $this->returnMakeFirstImage = $this->axZm->makeFirstImage($zoom, true); } } } // Imagesize of the initial image // We also need to know how big this initial image is, but only after it has been possibly made on the fly $zoom['config']['smallImgSize'] = $this->axZm->imageSize($zoom['config']['thumbDir'] . $zoom['config']['smallImgName'], $zoom['config']['im'], false); // 5. Filesize of the first image for internet connection speed test $zoom['config']['smallFileSize'] = filesize($zoom['config']['thumbDir'] . $zoom['config']['smallImgName']); // This will tell the javascript the dimensions of the initial picture if it is not already done and loaded via ajax // This happens if you load a new picture via javascript wich has not been "prepared" already. // In this case it will be prepared on the fly after calling it. The procedure can take a couple seconds. if (isset($_GET['setHW'])) { echo "<script type=\"text/javascript\">"; echo "\n\t\t\t\t\tjQuery.axZm['iw']=" . $this->ptj($zoom['config']['smallImgSize'][0]) . ";\n\t\t\t\t\tjQuery.axZm['ih']=" . $this->ptj($zoom['config']['smallImgSize'][1]) . ";\n\t\t\t\t\t"; echo "</script>"; if (!is_bool($this->returnMakeFirstImage)) { echo $this->returnMakeFirstImage; } // Do not exit here in order to make pyramid images or tiles on the fly too! // If $zoom['config']['pyrDialog'] OR $zoom['config']['gPyramidDialog'] is set to true // and tiles or image pyramid have to be generated, a "please wait" diolog will appear during this operation. // You can switch off this dialog by setting $zoom['config']['pyrDialog'] = false .... } // The following code will be executed only onece on window load... if (!isset($_GET['str'])) { if (!isset($_GET['setHW'])) { ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //// Get all initial image sizes for Image Gallery, but only on page load //////////////////////////////////////////// //// We will need to pass this parameters to and then from the gallery, when the user clicks on an different thumb /// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// foreach ($pic_list_array as $k => $v) { $zoomTmp['smallImgNameTemp'] = $this->composeFileName($v, $zoom['config']['picDim'], '_', $this->pngMod($zoom)); // Since not all initial pictures could have been generated, check their existence first // Generation of all initial pictures on the fly during first page load could take to long. if (file_exists($zoom['config']['thumbDir'] . $zoomTmp['smallImgNameTemp'])) { $pic_list_data[$k]['thumbSize'] = $this->axZm->imageSize($zoom['config']['thumbDir'] . $zoomTmp['smallImgNameTemp'], $zoom['config']['im'], false); } else { $pic_list_data[$k]['thumbSize'] = false; } } // Store information $zoom['config']['pic_list_data'] = $pic_list_data; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //// Generate all thumbs for Image Gallery on the fly, /////////////////////////////////////////////////////////////// //// Depending on the number of pictures and it's sizes this may take a while... ///////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Added the possibility to not generate thumbs if (!isset($zoom['config']['galleryNoThumbs']) or $zoom['config']['galleryNoThumbs'] === false) { $this->returnMakeAllThumbs = $this->axZm->makeAllThumbs($zoom); } else { $this->returnMakeAllThumbs = false; } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //// Image pyramid generation for selected zoomID, not all gallery list ////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if ($zoom['config']['gPyramid'] and $zoom['config']['gPyramidDir']) { // The subfolder name is the same as image name $zoomTmp['gPyramidPicDir'] = $zoom['config']['gPyramidDir'] . $this->getf('.', $zoom['config']['orgImgName']); // Check if pyramid images have been made already $zoomTmp['gPyramidPicDirExists'] = is_dir($zoomTmp['gPyramidPicDir']); // Make subfolder and generate the pyramid images, if they are not already made if (!$zoomTmp['gPyramidPicDirExists'] and !file_exists($zoom['config']['picDir'] . $this->getf('.', $zoom['config']['orgImgName']) . '.txt')) { $this->returnMakeZoomTiles = $this->axZm->gPyramid($zoom); if (isset($_GET['setHW']) and !is_bool($this->returnMakeZoomTiles)) { echo $this->returnMakeZoomTiles; } } elseif ($zoomTmp['gPyramidPicDirExists'] and $zoom['config']['gPyramidOverwrite'] and is_int($zoom['config']['gPyramidTime']) and strlen($zoom['config']['gPyramidTimeDim']) and !file_exists($zoom['config']['picDir'] . $this->getf('.', $zoom['config']['orgImgName']) . '.txt')) { $this->returnMakeZoomTiles = $this->axZm->gPyramid($zoom); if (isset($_GET['setHW']) and !is_bool($this->returnMakeZoomTiles)) { echo $this->returnMakeZoomTiles; } } // Changes chmod of all pyramid directories if ($zoom['config']['gPyramidChmodAll']) { $this->chmodAllDir($zoom['config']['gPyramidDir'], $zoom['config']['gPyramidChmod']); } } //////////////////////////////////////////////////////////////////////// /// Image tiles generation for selected zoomID, not all gallery list /// //////////////////////////////////////////////////////////////////////// if ($zoom['config']['pyrTiles'] and $zoom['config']['pyrTilesDir']) { $zoomTmp['thisTilesPicDir'] = $zoom['config']['pyrTilesDir'] . $this->getf('.', $zoom['config']['orgImgName']); if ($zoom['config']['orgImgSize'][0] >= $zoom['config']['tileSize'] or $zoom['config']['orgImgSize'][1] >= $zoom['config']['tileSize']) { $this->returnMakeZoomTiles = $this->axZm->zC($zoom, false); if (!file_exists($zoomTmp['thisTilesPicDir'] . '/0-0-0.' . $this->pngMod($zoom)) and !file_exists($zoom['config']['picDir'] . $this->getf('.', $zoom['config']['orgImgName']) . '.txt')) { $this->returnMakeZoomTiles = $this->axZm->makeZoomTiles($zoom); } if (isset($_GET['setHW']) and !is_bool($this->returnMakeZoomTiles) and $this->returnMakeZoomTiles) { echo $this->returnMakeZoomTiles; } } // Changes chmod matched with the config if ($zoom['config']['pyrChmodAll']) { $this->chmodAllDir($zoom['config']['pyrTilesDir'], $zoom['config']['pyrChmod']); } } ////////////////////////////////////////////////////////////////////////////////// // Generate code (an array) for the gallery, which will be passed to javascript // ////////////////////////////////////////////////////////////////////////////////// if (!isset($_GET['setHW'])) { // && ($zoom['config']['useGallery'] OR $zoom['config']['useFullGallery'] OR $zoom['config']['useHorGallery'] OR $zoom['config']['galleryNavi']) foreach ($pic_list_data as $k => $v) { $zoom['config']['galArray'][$k]['img'] = $v['fileName']; // Filename of the image $zoom['config']['galArray'][$k]['ow'] = $v['imgSize'][0]; // Width of original pic $zoom['config']['galArray'][$k]['oh'] = $v['imgSize'][1]; // Height of original pic $zoom['config']['galArray'][$k]['iw'] = $v['thumbSize'][0]; // Width of initial pic $zoom['config']['galArray'][$k]['ih'] = $v['thumbSize'][1]; // Height of initial pic $zoom['config']['galArray'][$k]['tD'] = $v['thumbDescr']; // Description under the thumb in the gallery $zoom['config']['galArray'][$k]['fD'] = $v['fullDescr']; // Full Description //$zoom['config']['galArray'][$k]['fT'] = $this->getl('.', $pic_list_array[$k]); //$zoom['config']['galArray'][$k]['fB'] = $this->getf('.', $pic_list_array[$k]); // Ver. 4.0 $zoom['config']['galArray'][$k]['mf'] = false; if ($zoom['config']['useMap'] && $zoom['config']['mapOwnImage'] && $zoom['config']['mapDir']) { $ownImageSize = explode('x', $zoom['config']['mapOwnImage']); $ownImageName = $this->composeFileName($v['fileName'], $ownImageSize[0] . 'x' . $ownImageSize[1], '_', $this->pngMod($zoom)); if (!file_exists($zoom['config']['mapDir'] . $ownImageName)) { $zoom['config']['galArray'][$k]['mf'] = true; } } if (isset($v['path'])) { // Note: this is absolute path to the image now $zoom['config']['galArray'][$k]['ph'] = $this->checkSlash($zoom['config']['pic'] . '/' . $v['path'], 'add'); // Image Path } // Check, whether pyramid or tiles have to be generated if ($zoom['config']['gPyramid']) { if (is_dir($zoom['config']['gPyramidDir'] . $this->getf('.', $v['fileName']))) { //$zoom['config']['galArray'][$k][9]=false; $zoom['config']['galArray'][$k]['mk'] = false; } else { $zoom['config']['galArray'][$k]['mk'] = 'gP'; } } elseif ($zoom['config']['pyrTiles']) { if ($v['imgSize'][0] < $zoom['config']['tileSize'] && $v['imgSize'][1] < $zoom['config']['tileSize'] or file_exists($zoom['config']['pyrTilesDir'] . $this->getf('.', $v['fileName']) . '/0-0-0.' . $this->pngMod($zoom))) { $zoom['config']['galArray'][$k]['mk'] = false; if ($zoom['config']['pyrAutoDetect']) { $thisTileSize = $this->axZm->imageSize($zoom['config']['pyrTilesDir'] . $this->getf('.', $v['fileName']) . '/0-0-0.' . $this->pngMod($zoom), $zoom['config']['im'], false); $zoom['config']['galArray'][$k]['ts'] = intval(max($thisTileSize[0], $thisTileSize[1])); } } else { $zoom['config']['galArray'][$k]['mk'] = 'tL'; } } else { $zoom['config']['galArray'][$k]['mk'] = false; } } // END: foreach ($pic_list_data as $k=>$v){ } // END: if (!isset($_GET['setHW'])){ } // END: if (!isset($_GET['str'])) if (isset($pic_list_data[$_GET['zoomID']]['path'])) { $zoom['config']['pic'] = $this->checkSlash($zoom['config']['pic'] . '/' . $pic_list_data[$_GET['zoomID']]['path'], 'add'); } } // END: if ($_GET['zoomID']) } else { unset($_GET['zoomID']); } return array($zoom, $zoomTmp); }
private function _addExif($filename) { //if ($_SERVER['SERVER_NAME'] == 'test.psychomorph') return true; try { $jpeg = new PelJpeg($filename); if (!($exif = $jpeg->getExif())) { // Create and add empty Exif data to the image (this throws away any old Exif data in the image). $exif = new PelExif(); $jpeg->setExif($exif); } if (!($tiff = $exif->getTiff())) { // Create and add TIFF data to the Exif data (Exif data is actually stored in a TIFF format). $tiff = new PelTiff(); $exif->setTiff($tiff); } if (!($ifd0 = $tiff->getIfd())) { // Create first Image File Directory and associate it with the TIFF data. $ifd0 = new PelIfd(PelIfd::IFD0); $tiff->setIfd($ifd0); } if (!($exif_ifd = $ifd0->getSubIfd(PelIfd::EXIF))) { // Create exif Image File Directory and associate it with the TIFF data. $exif_ifd = new PelIfd(PelIfd::EXIF); $ifd0->addSubIfd($exif_ifd); } if (!($ifd1 = $ifd0->getNextIfd())) { // thumbnail does not exist $ifd1 = new PelIfd(1); $ifd0->setNextIfd($ifd1); //$original = ImageCreateFromString($jpeg->getBytes()); # create image resource of original //$thumb = makeThumb($original); $thumb = $this->_makeThumb($this->getImage()); // start writing output to buffer ob_start(); // outputs thumb resource contents to buffer ImageJpeg($thumb); // create PelDataWindow from buffer thumb contents (and end output to buffer) $window = new PelDataWindow(ob_get_clean()); if ($window) { $ifd1->setThumbnail($window); # set window data as thumbnail in ifd1 } //imagedestroy($original); imagedestroy($thumb); } $exifdata = array(PelTag::IMAGE_DESCRIPTION => $this->getDescription(), PelTag::COPYRIGHT => "webmorph.org: " . $_SESSION['user_id'] . ': IMG_ID: ', PelTag::USER_COMMENT => $this->_embeddedTem); foreach ($exifdata as $PelTag => $val) { if ($PelTag == PelTag::USER_COMMENT) { if (!($entry = $exif_ifd->getEntry($PelTag))) { $exif_ifd->addEntry(new PelEntryUserComment($val)); } else { $entry->setValue($val); } } else { if (!($entry = $ifd0->getEntry($PelTag))) { $ifd0->addEntry(new PelEntryAscii($PelTag, $val)); } else { $entry->setValue($val); } } } $jpeg->saveFile($filename); return true; } catch (Exception $e) { // Handle exception echo $e; } }
/** * Generuje miniaturę i zapisuje do exifa * @param <type> $fullpath */ public function generujMiniature($fullpath) { // include_once('C:\xampp\php\PEAR\PelJpeg.php'); // include_once('C:\xampp\php\PEAR\PelExif.php'); // include_once('C:\xampp\php\PEAR\PelIfd.php'); $jpeg = new PelJpeg($fullpath); $exif = $jpeg->getExif(); //Jeżeli zdjęcie nie posiada exifa if (!$exif) { //Utworzenie kontera exif $pelexif = new PelExif(); //Dodanie obiektu PelTiff i PelIfd $tiff = new PelTiff(); $ifd0 = new PelIfd(PelIfd::IFD0); $tiff->setIfd($ifd0); $pelexif->setTiff($tiff); //Dodanie obiektów do zdjęcia $jpeg->setExif($pelexif); } $exif = $jpeg->getExif(); $tiff = $exif->getTiff(); $ifd0 = $tiff->getIfd(); $ifd1 = $ifd0->getNextIfd(); //tworzenie miniatury jeżli nie istnieje (nie ma IFD1) if (!$ifd1) { $ifd1 = new PelIfd(1); //point ifd0 to the new ifd1 (or else ifd1 will not be read) $ifd0->setNextIfd($ifd1); //create image resource of original $original = ImageCreateFromString($jpeg->getBytes()); $orig_w = imagesx($original); $orig_h = imagesy($original); $wmax = 160; $hmax = 120; if ($orig_w > $wmax || $orig_h > $hmax) { $thumb_w = $wmax; $thumb_h = $hmax; if ($thumb_w / $orig_w * $orig_h > $thumb_h) { $thumb_w = round($thumb_h * $orig_w / $orig_h); } else { $thumb_h = round($thumb_w * $orig_h / $orig_w); } } else { # only set the thumb's size if the original is larger than 'wmax'x'hmax' $thumb_w = $orig_w; $thumb_h = $orig_h; } # create image resource with thumbnail sizing $thumb = imagecreatetruecolor($thumb_w, $thumb_h); ## Resize original and copy to the blank thumb resource imagecopyresampled($thumb, $original, 0, 0, 0, 0, $thumb_w, $thumb_h, $orig_w, $orig_h); # start writing output to buffer ob_start(); # outputs thumb resource contents to buffer ImageJpeg($thumb); # create PelDataWindow from buffer thumb contents (and end output to buffer) $window = new PelDataWindow(ob_get_clean()); if ($window) { $ifd1->setThumbnail($window); # set window data as thumbnail in ifd1 $outpath = $fullpath; # overwrite original jpg file file_put_contents($outpath, $jpeg->getBytes()); # write everything to output filename } } }
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(); }
private function createNewImageGD($sourcePathBase, $targetPath, $newWidth, $newHeight, $sourceWidth, $sourceHeight) { $status = false; if (!$this->sourceGdImg) { $this->sourceGdImg = imagecreatefromjpeg($sourcePathBase); if (class_exists('PelJpeg')) { $inputJpg = new PelJpeg($sourcePathBase); $this->exif = $inputJpg->getExif(); } } ini_set('memory_limit', '512M'); $tmpImg = imagecreatetruecolor($newWidth, $newHeight); //imagecopyresampled($tmpImg,$sourceImg,0,0,0,0,$newWidth,$newHeight,$sourceWidth,$sourceHeight); imagecopyresized($tmpImg, $this->sourceGdImg, 0, 0, 0, 0, $newWidth, $newHeight, $sourceWidth, $sourceHeight); if ($this->jpgCompression) { $status = imagejpeg($tmpImg, $targetPath, $this->jpgCompression); if ($this->exif && class_exists('PelJpeg')) { $outputJpg = new PelJpeg($targetPath); $outputJpg->setExif($this->exif); $outputJpg->saveFile($targetPath); } } else { if ($this->exif && class_exists('PelJpeg')) { $outputJpg = new PelJpeg($tmpImg); $outputJpg->setExif($this->exif); $status = $outputJpg->saveFile($targetPath); } else { $status = imagejpeg($tmpImg, $targetPath); } } if (!$status) { $this->logOrEcho("\tERROR: Unable to resize and write file: " . $targetPath . "\n"); } imagedestroy($tmpImg); return $status; }