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->assertEquals($subject, $written_subject->getValue()); }
public 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); }
private function saveToJpeg() { $jpegFile = new pel\PelJpeg($this->filePath); $exif = $jpegFile->getExif(); $tiff = $exif->getTiff(); $ifd0 = $tiff->getIfd(); switch ($this->tag) { case 'Description': $ifd0->addEntry(new pel\PelEntryAscii(pel\PelTag::IMAGE_DESCRIPTION, $this->value)); break; default: break; } $jpegFile->saveFile($this->filePath); $this->refreshDatabase(); print 'save se povedlo'; header("Refresh:5; url=index.php", true, 303); }
function testThisDoesNotWorkAsExpected() { $tmpfile = dirname(__FILE__) . '/images/bug1730993_tmp.jpg'; $bigfile = dirname(__FILE__) . '/images/bug1730993_large.jpg'; // TODO: Should not throw exception return; try { require_once 'PelJpeg.php'; $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 exception: ' . $e->getMessage()); } }
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->assertEquals($exif, $exifin); }
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); $output_jpeg->saveFile($output);
println(); println('The files will be renamed based on their Exif timestamp.'); exit(1); } /* * We typically need lots of RAM to parse TIFF images since they tend * to be big and uncompressed. */ ini_set('memory_limit', '32M'); foreach ($argv as $file) { println('Reading file "%s".', $file); $data = new PelDataWindow(file_get_contents($file)); if (PelJpeg::isValid($data)) { $jpeg = new PelJpeg(); $jpeg->load($data); $app1 = $jpeg->getExif(); $tiff = $app1->getTiff(); } elseif (PelTiff::isValid($data)) { $tiff = new PelTiff($data); } else { println('Unrecognized image format! Skipping.'); continue; } $ifd0 = $tiff->getIfd(); $entry = $ifd0->getEntry(PelTag::DATE_TIME); if ($entry == null) { println('Skipping %s because no DATE_TIME tag was found.', $file); continue; } $time = $entry->getValue(); do {
public function testRead() { Pel::clearExceptions(); Pel::setStrictParsing(false); $jpeg = new PelJpeg(dirname(__FILE__) . '/nikon-coolscan-iv.jpg'); $exif = $jpeg->getExif(); $this->assertInstanceOf('lsolesen\\pel\\PelExif', $exif); $tiff = $exif->getTiff(); $this->assertInstanceOf('lsolesen\\pel\\PelTiff', $tiff); /* The first IFD. */ $ifd0 = $tiff->getIfd(); $this->assertInstanceOf('lsolesen\\pel\\PelIfd', $ifd0); /* Start of IDF $ifd0. */ $this->assertEquals(count($ifd0->getEntries()), 6); $entry = $ifd0->getEntry(271); // Make $this->assertInstanceOf('lsolesen\\pel\\PelEntryAscii', $entry); $this->assertEquals($entry->getValue(), 'Nikon'); $this->assertEquals($entry->getText(), 'Nikon'); $entry = $ifd0->getEntry(282); // XResolution $this->assertInstanceOf('lsolesen\\pel\\PelEntryRational', $entry); $this->assertEquals($entry->getValue(), array(0 => 2000, 1 => 1)); $this->assertEquals($entry->getText(), '2000/1'); $entry = $ifd0->getEntry(283); // YResolution $this->assertInstanceOf('lsolesen\\pel\\PelEntryRational', $entry); $this->assertEquals($entry->getValue(), array(0 => 2000, 1 => 1)); $this->assertEquals($entry->getText(), '2000/1'); $entry = $ifd0->getEntry(296); // ResolutionUnit $this->assertInstanceOf('lsolesen\\pel\\PelEntryShort', $entry); $this->assertEquals($entry->getValue(), 2); $this->assertEquals($entry->getText(), 'Inch'); $entry = $ifd0->getEntry(306); // DateTime $this->assertInstanceOf('lsolesen\\pel\\PelEntryTime', $entry); $this->assertEquals($entry->getValue(), 1090023875); $this->assertEquals($entry->getText(), '2004:07:17 00:24:35'); $entry = $ifd0->getEntry(531); // YCbCrPositioning $this->assertInstanceOf('lsolesen\\pel\\PelEntryShort', $entry); $this->assertEquals($entry->getValue(), 1); $this->assertEquals($entry->getText(), 'centered'); /* Sub IFDs of $ifd0. */ $this->assertEquals(count($ifd0->getSubIfds()), 2); $ifd0_0 = $ifd0->getSubIfd(2); // IFD Exif $this->assertInstanceOf('lsolesen\\pel\\PelIfd', $ifd0_0); /* Start of IDF $ifd0_0. */ $this->assertEquals(count($ifd0_0->getEntries()), 7); $entry = $ifd0_0->getEntry(36864); // ExifVersion $this->assertInstanceOf('lsolesen\\pel\\PelEntryVersion', $entry); $this->assertEquals($entry->getValue(), 2.1); $this->assertEquals($entry->getText(), 'Exif Version 2.1'); $entry = $ifd0_0->getEntry(37121); // ComponentsConfiguration $this->assertInstanceOf('lsolesen\\pel\\PelEntryUndefined', $entry); $this->assertEquals($entry->getValue(), ""); $this->assertEquals($entry->getText(), 'Y Cb Cr -'); $entry = $ifd0_0->getEntry(37500); // MakerNote $this->assertInstanceOf('lsolesen\\pel\\PelEntryUndefined', $entry); $expected = "0100"; $this->assertEquals($entry->getValue(), $expected); $this->assertEquals($entry->getText(), '32 bytes unknown MakerNote data'); $entry = $ifd0_0->getEntry(40960); // FlashPixVersion $this->assertInstanceOf('lsolesen\\pel\\PelEntryVersion', $entry); $this->assertEquals($entry->getValue(), 1); $this->assertEquals($entry->getText(), 'FlashPix Version 1.0'); $entry = $ifd0_0->getEntry(40961); // ColorSpace $this->assertInstanceOf('lsolesen\\pel\\PelEntryShort', $entry); $this->assertEquals($entry->getValue(), 1); $this->assertEquals($entry->getText(), 'sRGB'); $entry = $ifd0_0->getEntry(40962); // PixelXDimension $this->assertInstanceOf('lsolesen\\pel\\PelEntryLong', $entry); $this->assertEquals($entry->getValue(), 960); $this->assertEquals($entry->getText(), '960'); $entry = $ifd0_0->getEntry(40963); // PixelYDimension $this->assertInstanceOf('lsolesen\\pel\\PelEntryLong', $entry); $this->assertEquals($entry->getValue(), 755); $this->assertEquals($entry->getText(), '755'); /* Sub IFDs of $ifd0_0. */ $this->assertEquals(count($ifd0_0->getSubIfds()), 0); $this->assertEquals($ifd0_0->getThumbnailData(), ''); /* Next IFD. */ $ifd0_1 = $ifd0_0->getNextIfd(); $this->assertNull($ifd0_1); /* End of IFD $ifd0_0. */ $ifd0_1 = $ifd0->getSubIfd(3); // IFD GPS $this->assertInstanceOf('lsolesen\\pel\\PelIfd', $ifd0_1); /* Start of IDF $ifd0_1. */ $this->assertEquals(count($ifd0_1->getEntries()), 0); /* Sub IFDs of $ifd0_1. */ $this->assertEquals(count($ifd0_1->getSubIfds()), 0); $this->assertEquals($ifd0_1->getThumbnailData(), ''); /* Next IFD. */ $ifd0_2 = $ifd0_1->getNextIfd(); $this->assertNull($ifd0_2); /* End of IFD $ifd0_1. */ $this->assertEquals($ifd0->getThumbnailData(), ''); /* Next IFD. */ $ifd1 = $ifd0->getNextIfd(); $this->assertNull($ifd1); /* End of IFD $ifd0. */ $this->assertTrue(count(Pel::getExceptions()) == 0); }