本文整理汇总了PHP中PelJpeg::getExif方法的典型用法代码示例。如果您正苦于以下问题:PHP PelJpeg::getExif方法的具体用法?PHP PelJpeg::getExif怎么用?PHP PelJpeg::getExif使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PelJpeg
的用法示例。
在下文中一共展示了PelJpeg::getExif方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* Loads the EXIF data from the given file and returns it
*
* @param $filename Filename of the file to load the exif data from
* @return The EXIF data as array
*/
public function load($filename)
{
if (!file_exists($filename)) {
throw new Exception('File "' . $filename . '" not found!');
}
$jpeg = new PelJpeg($filename);
$exif = array(PelIfd::IFD0 => $jpeg->getExif()->getTiff()->getIfd(), PelIfd::IFD1 => $jpeg->getExif()->getTiff()->getIfd()->getNextIfd(), PelIfd::EXIF => $jpeg->getExif()->getTiff()->getIfd()->getSubIfd(PelIfd::EXIF), PelIfd::GPS => $jpeg->getExif()->getTiff()->getIfd()->getSubIfd(PelIfd::GPS));
$result = array('id' => $this->getDescriptionPart($exif, 'id'), 'Model' => str_replace('\\0', '', $this->getValue($exif[PelIfd::IFD0]->getEntry(PelTag::MODEL))), 'Flash' => $this->getValue($exif[PelIfd::EXIF]->getEntry(PelTag::FLASH)), 'LensID' => $this->parseXmpData($filename, 'aux:LensID') != '' ? $this->parseXmpData($filename, 'aux:LensID') : '0', 'Lens' => $this->parseXmpData($filename, 'aux:Lens'), 'ExposureProgram' => $this->getValue($exif[PelIfd::EXIF]->getEntry(PelTag::EXPOSURE_PROGRAM)), 'MeteringMode' => $this->getValue($exif[PelIfd::EXIF]->getEntry(PelTag::METERING_MODE)), 'Title' => $this->getDescriptionPart($exif, 'Title'), 'Description' => $this->getDescriptionPart($exif, 'Description'), 'Category' => $this->getDescriptionPart($exif, 'Category'), 'Tags' => explode(',', $this->getDescriptionPart($exif, 'Tags')), 'DateCreated' => date('Y-m-d H:i:s', $this->getValue($exif[PelIfd::EXIF]->getEntry(PelTag::DATE_TIME_ORIGINAL)) != "" ? $this->getValue($exif[PelIfd::EXIF]->getEntry(PelTag::DATE_TIME_ORIGINAL)) : $this->getValue($exif[PelIfd::EXIF]->getEntry(PelTag::DATE_TIME_DIGITIZED))), 'FocalLength' => $this->getFocalLength($exif), 'FNumber' => $this->getFNumber($exif), 'ExposureTime' => $this->getExposureTime($exif), 'ISO' => $this->getValue($exif[PelIfd::EXIF]->getEntry(PelTag::ISO_SPEED_RATINGS)), 'GpsLatitudeRef' => isset($exif[PelIfd::GPS]) ? $this->getValue($exif[PelIfd::GPS]->getEntry(PelTag::GPS_LATITUDE_REF)) : '', 'GpsLatitude' => isset($exif[PelIfd::GPS]) ? $this->gpsExtract($exif[PelIfd::GPS]->getEntry(PelTag::GPS_LATITUDE)->getValue()) : '', 'GpsLongitudeRef' => isset($exif[PelIfd::GPS]) ? $this->getValue($exif[PelIfd::GPS]->getEntry(PelTag::GPS_LONGITUDE_REF)) : '', 'GpsLongitude' => isset($exif[PelIfd::GPS]) ? $this->gpsExtract($exif[PelIfd::GPS]->getEntry(PelTag::GPS_LONGITUDE)->getValue()) : '');
return $result;
}
示例2: testThisDoesNotWorkAsExpected
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());
}
示例3: testRead
function testRead()
{
Pel::clearExceptions();
Pel::setStrictParsing(false);
$jpeg = new PelJpeg(dirname(__FILE__) . '/no-exif.jpg');
$exif = $jpeg->getExif();
$this->assertNull($exif);
$this->assertTrue(count(Pel::getExceptions()) == 0);
}
示例4: addGPSdata
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;
}
示例5: testThisDoesNotWorkAsExpected
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');
}
}
示例6: testThisDoesNotWorkAsExpected
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);
}
示例7: testWriteRead
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');
}
示例8: _addExif
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;
}
}
示例9: testRead
function testRead()
{
Pel::clearExceptions();
Pel::setStrictParsing(false);
$jpeg = new PelJpeg(dirname(__FILE__) . '/olympus-c50z.jpg');
$exif = $jpeg->getExif();
$this->assertIsA($exif, 'PelExif');
$tiff = $exif->getTiff();
$this->assertIsA($tiff, 'PelTiff');
/* The first IFD. */
$ifd0 = $tiff->getIfd();
$this->assertIsA($ifd0, 'PelIfd');
/* Start of IDF $ifd0. */
$this->assertEqual(count($ifd0->getEntries()), 11);
$entry = $ifd0->getEntry(270);
// ImageDescription
$this->assertIsA($entry, 'PelEntryAscii');
$this->assertEqual($entry->getValue(), 'OLYMPUS DIGITAL CAMERA ');
$this->assertEqual($entry->getText(), 'OLYMPUS DIGITAL CAMERA ');
$entry = $ifd0->getEntry(271);
// Make
$this->assertIsA($entry, 'PelEntryAscii');
$this->assertEqual($entry->getValue(), 'OLYMPUS OPTICAL CO.,LTD');
$this->assertEqual($entry->getText(), 'OLYMPUS OPTICAL CO.,LTD');
$entry = $ifd0->getEntry(272);
// Model
$this->assertIsA($entry, 'PelEntryAscii');
$this->assertEqual($entry->getValue(), 'X-2,C-50Z ');
$this->assertEqual($entry->getText(), 'X-2,C-50Z ');
$entry = $ifd0->getEntry(274);
// Orientation
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 1);
$this->assertEqual($entry->getText(), 'top - left');
$entry = $ifd0->getEntry(282);
// XResolution
$this->assertIsA($entry, 'PelEntryRational');
$this->assertEqual($entry->getValue(), array(0 => 144, 1 => 1));
$this->assertEqual($entry->getText(), '144/1');
$entry = $ifd0->getEntry(283);
// YResolution
$this->assertIsA($entry, 'PelEntryRational');
$this->assertEqual($entry->getValue(), array(0 => 144, 1 => 1));
$this->assertEqual($entry->getText(), '144/1');
$entry = $ifd0->getEntry(296);
// ResolutionUnit
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 2);
$this->assertEqual($entry->getText(), 'Inch');
$entry = $ifd0->getEntry(305);
// Software
$this->assertIsA($entry, 'PelEntryAscii');
$this->assertEqual($entry->getValue(), '28-1012 ');
$this->assertEqual($entry->getText(), '28-1012 ');
$entry = $ifd0->getEntry(306);
// DateTime
$this->assertIsA($entry, 'PelEntryTime');
$this->assertEqual($entry->getValue(), false);
$this->assertEqual($entry->getText(), '0000:00:00 00:00:00');
$entry = $ifd0->getEntry(531);
// YCbCrPositioning
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 2);
$this->assertEqual($entry->getText(), 'co-sited');
$entry = $ifd0->getEntry(50341);
// PrintIM
$this->assertIsA($entry, 'PelEntryUndefined');
$this->assertEqual($entry->getValue(), 'PrintIM0250ˆ
Ð
èÿ€€€€€€€€€ \'\'—\'°\'\'^\'‹\'Ë\'å\'');
$this->assertEqual($entry->getText(), '(undefined)');
/* Sub IFDs of $ifd0. */
$this->assertEqual(count($ifd0->getSubIfds()), 1);
$ifd0_0 = $ifd0->getSubIfd(2);
// IFD Exif
$this->assertIsA($ifd0_0, 'PelIfd');
/* Start of IDF $ifd0_0. */
$this->assertEqual(count($ifd0_0->getEntries()), 30);
$entry = $ifd0_0->getEntry(33434);
// ExposureTime
$this->assertIsA($entry, 'PelEntryRational');
$this->assertEqual($entry->getValue(), array(0 => 1, 1 => 80));
$this->assertEqual($entry->getText(), '1/80 sec.');
$entry = $ifd0_0->getEntry(33437);
// FNumber
$this->assertIsA($entry, 'PelEntryRational');
$this->assertEqual($entry->getValue(), array(0 => 45, 1 => 10));
$this->assertEqual($entry->getText(), 'f/4.5');
$entry = $ifd0_0->getEntry(34850);
// ExposureProgram
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 5);
$this->assertEqual($entry->getText(), 'Creative program (biased toward depth of field)');
$entry = $ifd0_0->getEntry(34855);
// ISOSpeedRatings
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 80);
$this->assertEqual($entry->getText(), '80');
$entry = $ifd0_0->getEntry(36864);
// ExifVersion
//.........这里部分代码省略.........
示例10: testRead
function testRead()
{
Pel::clearExceptions();
Pel::setStrictParsing(false);
$jpeg = new PelJpeg(dirname(__FILE__) . '/sony-dsc-v1.jpg');
$exif = $jpeg->getExif();
$this->assertIsA($exif, 'PelExif');
$tiff = $exif->getTiff();
$this->assertIsA($tiff, 'PelTiff');
/* The first IFD. */
$ifd0 = $tiff->getIfd();
$this->assertIsA($ifd0, 'PelIfd');
/* Start of IDF $ifd0. */
$this->assertEqual(count($ifd0->getEntries()), 10);
$entry = $ifd0->getEntry(270);
// ImageDescription
$this->assertIsA($entry, 'PelEntryAscii');
$this->assertEqual($entry->getValue(), ' ');
$this->assertEqual($entry->getText(), ' ');
$entry = $ifd0->getEntry(271);
// Make
$this->assertIsA($entry, 'PelEntryAscii');
$this->assertEqual($entry->getValue(), 'SONY');
$this->assertEqual($entry->getText(), 'SONY');
$entry = $ifd0->getEntry(272);
// Model
$this->assertIsA($entry, 'PelEntryAscii');
$this->assertEqual($entry->getValue(), 'DSC-V1');
$this->assertEqual($entry->getText(), 'DSC-V1');
$entry = $ifd0->getEntry(274);
// Orientation
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 6);
$this->assertEqual($entry->getText(), 'right - top');
$entry = $ifd0->getEntry(282);
// XResolution
$this->assertIsA($entry, 'PelEntryRational');
$this->assertEqual($entry->getValue(), array(0 => 72, 1 => 1));
$this->assertEqual($entry->getText(), '72/1');
$entry = $ifd0->getEntry(283);
// YResolution
$this->assertIsA($entry, 'PelEntryRational');
$this->assertEqual($entry->getValue(), array(0 => 72, 1 => 1));
$this->assertEqual($entry->getText(), '72/1');
$entry = $ifd0->getEntry(296);
// ResolutionUnit
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 2);
$this->assertEqual($entry->getText(), 'Inch');
$entry = $ifd0->getEntry(306);
// DateTime
$this->assertIsA($entry, 'PelEntryTime');
$this->assertEqual($entry->getValue(), 1089482993);
$this->assertEqual($entry->getText(), '2004:07:10 18:09:53');
$entry = $ifd0->getEntry(531);
// YCbCrPositioning
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 2);
$this->assertEqual($entry->getText(), 'co-sited');
$entry = $ifd0->getEntry(50341);
// PrintIM
$this->assertIsA($entry, 'PelEntryUndefined');
$this->assertEqual($entry->getValue(), 'PrintIM' . "" . '0250' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '');
$this->assertEqual($entry->getText(), '(undefined)');
/* Sub IFDs of $ifd0. */
$this->assertEqual(count($ifd0->getSubIfds()), 1);
$ifd0_0 = $ifd0->getSubIfd(2);
// IFD Exif
$this->assertIsA($ifd0_0, 'PelIfd');
/* Start of IDF $ifd0_0. */
$this->assertEqual(count($ifd0_0->getEntries()), 26);
$entry = $ifd0_0->getEntry(33434);
// ExposureTime
$this->assertIsA($entry, 'PelEntryRational');
$this->assertEqual($entry->getValue(), array(0 => 10, 1 => 600));
$this->assertEqual($entry->getText(), '1/60 sec.');
$entry = $ifd0_0->getEntry(33437);
// FNumber
$this->assertIsA($entry, 'PelEntryRational');
$this->assertEqual($entry->getValue(), array(0 => 32, 1 => 10));
$this->assertEqual($entry->getText(), 'f/3.2');
$entry = $ifd0_0->getEntry(34850);
// ExposureProgram
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 2);
$this->assertEqual($entry->getText(), 'Normal program');
$entry = $ifd0_0->getEntry(34855);
// ISOSpeedRatings
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 100);
$this->assertEqual($entry->getText(), '100');
$entry = $ifd0_0->getEntry(36864);
// ExifVersion
$this->assertIsA($entry, 'PelEntryVersion');
$this->assertEqual($entry->getValue(), 2.2);
$this->assertEqual($entry->getText(), 'Exif Version 2.2');
$entry = $ifd0_0->getEntry(36867);
// DateTimeOriginal
$this->assertIsA($entry, 'PelEntryTime');
$this->assertEqual($entry->getValue(), 1089482993);
//.........这里部分代码省略.........
示例11: addExif
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;
}
}
示例12: testRead
function testRead()
{
Pel::clearExceptions();
Pel::setStrictParsing(false);
$jpeg = new PelJpeg(dirname(__FILE__) . '/olympus-c765uz.jpg');
$exif = $jpeg->getExif();
$this->assertIsA($exif, 'PelExif');
$tiff = $exif->getTiff();
$this->assertIsA($tiff, 'PelTiff');
/* The first IFD. */
$ifd0 = $tiff->getIfd();
$this->assertIsA($ifd0, 'PelIfd');
/* Start of IDF $ifd0. */
$this->assertEqual(count($ifd0->getEntries()), 11);
$entry = $ifd0->getEntry(270);
// ImageDescription
$this->assertIsA($entry, 'PelEntryAscii');
$this->assertEqual($entry->getValue(), 'OLYMPUS DIGITAL CAMERA ');
$this->assertEqual($entry->getText(), 'OLYMPUS DIGITAL CAMERA ');
$entry = $ifd0->getEntry(271);
// Make
$this->assertIsA($entry, 'PelEntryAscii');
$this->assertEqual($entry->getValue(), 'OLYMPUS CORPORATION');
$this->assertEqual($entry->getText(), 'OLYMPUS CORPORATION');
$entry = $ifd0->getEntry(272);
// Model
$this->assertIsA($entry, 'PelEntryAscii');
$this->assertEqual($entry->getValue(), 'C765UZ');
$this->assertEqual($entry->getText(), 'C765UZ');
$entry = $ifd0->getEntry(274);
// Orientation
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 1);
$this->assertEqual($entry->getText(), 'top - left');
$entry = $ifd0->getEntry(282);
// XResolution
$this->assertIsA($entry, 'PelEntryRational');
$this->assertEqual($entry->getValue(), array(0 => 72, 1 => 1));
$this->assertEqual($entry->getText(), '72/1');
$entry = $ifd0->getEntry(283);
// YResolution
$this->assertIsA($entry, 'PelEntryRational');
$this->assertEqual($entry->getValue(), array(0 => 72, 1 => 1));
$this->assertEqual($entry->getText(), '72/1');
$entry = $ifd0->getEntry(296);
// ResolutionUnit
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 2);
$this->assertEqual($entry->getText(), 'Inch');
$entry = $ifd0->getEntry(305);
// Software
$this->assertIsA($entry, 'PelEntryAscii');
$this->assertEqual($entry->getValue(), 'v777-76');
$this->assertEqual($entry->getText(), 'v777-76');
$entry = $ifd0->getEntry(306);
// DateTime
$this->assertIsA($entry, 'PelEntryTime');
$this->assertEqual($entry->getValue(), 1090073972);
$this->assertEqual($entry->getText(), '2004:07:17 14:19:32');
$entry = $ifd0->getEntry(531);
// YCbCrPositioning
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 2);
$this->assertEqual($entry->getText(), 'co-sited');
$entry = $ifd0->getEntry(50341);
// PrintIM
$this->assertIsA($entry, 'PelEntryUndefined');
$this->assertEqual($entry->getValue(), 'PrintIM' . "" . '0250' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . ' ' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '
' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . 'а' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '
' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . 'ш' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . 'џ' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . ' ' . "" . '' . "" . '\'' . "" . '' . "" . '' . "" . '' . "" . '\'' . "" . '' . "" . '' . "" . '' . "" . '\'' . "" . '' . "" . 'А' . "" . '' . "" . '\'' . "" . '' . "" . '' . "" . '' . "" . '\'' . "" . '' . "" . '^' . "" . '' . "" . '\'' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '\'' . "" . '' . "" . 'Ы' . "" . '' . "" . '\'' . "" . '' . "" . 'х' . "" . '' . "" . '\'' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '' . "" . '!' . "" . '' . "" . '' . "" . '' . "" . '' . "" . 'И' . "" . '' . "" . '');
$this->assertEqual($entry->getText(), '(undefined)');
/* Sub IFDs of $ifd0. */
$this->assertEqual(count($ifd0->getSubIfds()), 1);
$ifd0_0 = $ifd0->getSubIfd(2);
// IFD Exif
$this->assertIsA($ifd0_0, 'PelIfd');
/* Start of IDF $ifd0_0. */
$this->assertEqual(count($ifd0_0->getEntries()), 32);
$entry = $ifd0_0->getEntry(33434);
// ExposureTime
$this->assertIsA($entry, 'PelEntryRational');
$this->assertEqual($entry->getValue(), array(0 => 10, 1 => 2000));
$this->assertEqual($entry->getText(), '1/200 sec.');
$entry = $ifd0_0->getEntry(33437);
// FNumber
$this->assertIsA($entry, 'PelEntryRational');
$this->assertEqual($entry->getValue(), array(0 => 32, 1 => 10));
$this->assertEqual($entry->getText(), 'f/3.2');
$entry = $ifd0_0->getEntry(34850);
// ExposureProgram
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 5);
$this->assertEqual($entry->getText(), 'Creative program (biased toward depth of field)');
$entry = $ifd0_0->getEntry(34855);
// ISOSpeedRatings
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 64);
$this->assertEqual($entry->getText(), '64');
$entry = $ifd0_0->getEntry(36864);
// ExifVersion
//.........这里部分代码省略.........
示例13: testRead
function testRead()
{
Pel::clearExceptions();
Pel::setStrictParsing(false);
$jpeg = new PelJpeg(dirname(__FILE__) . '/leica-d-lux.jpg');
$exif = $jpeg->getExif();
$this->assertIsA($exif, 'PelExif');
$tiff = $exif->getTiff();
$this->assertIsA($tiff, 'PelTiff');
/* The first IFD. */
$ifd0 = $tiff->getIfd();
$this->assertIsA($ifd0, 'PelIfd');
/* Start of IDF $ifd0. */
$this->assertEqual(count($ifd0->getEntries()), 10);
$entry = $ifd0->getEntry(271);
// Make
$this->assertIsA($entry, 'PelEntryAscii');
$this->assertEqual($entry->getValue(), 'LEICA');
$this->assertEqual($entry->getText(), 'LEICA');
$entry = $ifd0->getEntry(272);
// Model
$this->assertIsA($entry, 'PelEntryAscii');
$this->assertEqual($entry->getValue(), 'D-LUX');
$this->assertEqual($entry->getText(), 'D-LUX');
$entry = $ifd0->getEntry(274);
// Orientation
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 1);
$this->assertEqual($entry->getText(), 'top - left');
$entry = $ifd0->getEntry(282);
// XResolution
$this->assertIsA($entry, 'PelEntryRational');
$this->assertEqual($entry->getValue(), array(0 => 72, 1 => 1));
$this->assertEqual($entry->getText(), '72/1');
$entry = $ifd0->getEntry(283);
// YResolution
$this->assertIsA($entry, 'PelEntryRational');
$this->assertEqual($entry->getValue(), array(0 => 72, 1 => 1));
$this->assertEqual($entry->getText(), '72/1');
$entry = $ifd0->getEntry(296);
// ResolutionUnit
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 2);
$this->assertEqual($entry->getText(), 'Inch');
$entry = $ifd0->getEntry(305);
// Software
$this->assertIsA($entry, 'PelEntryAscii');
$this->assertEqual($entry->getValue(), 'Ver1.06');
$this->assertEqual($entry->getText(), 'Ver1.06');
$entry = $ifd0->getEntry(306);
// DateTime
$this->assertIsA($entry, 'PelEntryTime');
$this->assertEqual($entry->getValue(), 1099994128);
$this->assertEqual($entry->getText(), '2004:11:09 09:55:28');
$entry = $ifd0->getEntry(531);
// YCbCrPositioning
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 2);
$this->assertEqual($entry->getText(), 'co-sited');
$entry = $ifd0->getEntry(50341);
// PrintIM
$this->assertIsA($entry, 'PelEntryUndefined');
$this->assertEqual($entry->getValue(), 'PrintIM0250d
¬
Ä€ \'\'7\'°\'\'^\'‹\'Ë\'å\'');
$this->assertEqual($entry->getText(), '(undefined)');
/* Sub IFDs of $ifd0. */
$this->assertEqual(count($ifd0->getSubIfds()), 1);
$ifd0_0 = $ifd0->getSubIfd(2);
// IFD Exif
$this->assertIsA($ifd0_0, 'PelIfd');
/* Start of IDF $ifd0_0. */
$this->assertEqual(count($ifd0_0->getEntries()), 37);
$entry = $ifd0_0->getEntry(33434);
// ExposureTime
$this->assertIsA($entry, 'PelEntryRational');
$this->assertEqual($entry->getValue(), array(0 => 10, 1 => 1000));
$this->assertEqual($entry->getText(), '1/100 sec.');
$entry = $ifd0_0->getEntry(33437);
// FNumber
$this->assertIsA($entry, 'PelEntryRational');
$this->assertEqual($entry->getValue(), array(0 => 97, 1 => 10));
$this->assertEqual($entry->getText(), 'f/9.7');
$entry = $ifd0_0->getEntry(34850);
// ExposureProgram
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 2);
$this->assertEqual($entry->getText(), 'Normal program');
$entry = $ifd0_0->getEntry(34855);
// ISOSpeedRatings
$this->assertIsA($entry, 'PelEntryShort');
$this->assertEqual($entry->getValue(), 100);
$this->assertEqual($entry->getText(), '100');
$entry = $ifd0_0->getEntry(36864);
// ExifVersion
$this->assertIsA($entry, 'PelEntryVersion');
$this->assertEqual($entry->getValue(), 2.2);
$this->assertEqual($entry->getText(), 'Exif Version 2.2');
$entry = $ifd0_0->getEntry(36867);
// DateTimeOriginal
//.........这里部分代码省略.........
示例14: saveEdit
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');
//.........这里部分代码省略.........
示例15: jpegToTest
function jpegToTest($name, PelJpeg $jpeg)
{
$exif = $jpeg->getExif();
println('$exif = %s->getExif();', $name);
if ($exif == null) {
println('$this->assertNull($exif);');
} else {
jpegContentToTest('$exif', $exif);
}
}