示例#1
0
文件: read-write.php 项目: ni-c/pel
 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');
 }
示例#2
0
    println('Reading file "%s".', $file);
    $data = new PelDataWindow(file_get_contents($file));
    if (PelJpeg::isValid($data)) {
        $jpeg = new PelJpeg();
        $jpeg->load($data);
        $app1 = $jpeg->getExif();
        if ($app1 == null) {
            println('Skipping %s because no APP1 section was found.', $file);
            continue;
        }
        $tiff = $app1->getTiff();
    } elseif (PelTiff::isValid($data)) {
        $tiff = new PelTiff($data);
    } else {
        println('Unrecognized image format! Skipping.');
        continue;
    }
    $ifd0 = $tiff->getIfd();
    $entry = $ifd0->getEntry(PelTag::DATE_TIME);
    if ($entry == null) {
        println('Skipping %s because no DATE_TIME tag was found.', $file);
        continue;
    }
    $time = $entry->getValue();
    $new = gmdate('../Y-m/', $time) . $file;
    if (file_exists($new)) {
        die('Aborting, ' . $new . ' exists!');
    }
    println('mv %s %s', $file, $new);
    rename($file, $new);
}
示例#3
0
function tiffToTest($name, PelTiff $tiff)
{
    println();
    println('/* The first IFD. */');
    println('$ifd0 = %s->getIfd();', $name);
    $ifd = $tiff->getIfd();
    if ($ifd instanceof PelIfd) {
        println('$this->assertIsA($ifd0, \'PelIfd\');');
        ifdToTest('$ifd', 0, $ifd);
    } else {
        println('$this->assertNull($ifd0);');
    }
}