0fdf9ceb7f16be9f02cb1f1b75315443a6ea0bc0
[yaffs-website] / vendor / lsolesen / pel / test / Bug3017880Test.php
1 <?php
2
3 /**
4  * PEL: PHP Exif Library.
5  * A library with support for reading and
6  * writing all Exif headers in JPEG and TIFF images using PHP.
7  *
8  * Copyright (C) 2004, 2006, 2007 Martin Geisler.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program in the file COPYING; if not, write to the
22  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23  * Boston, MA 02110-1301 USA
24  */
25
26 use lsolesen\pel\PelJpeg;
27 use lsolesen\pel\PelExif;
28 use lsolesen\pel\PelTiff;
29 use lsolesen\pel\PelIfd;
30 use lsolesen\pel\PelTag;
31 use lsolesen\pel\PelEntryAscii;
32
33 class Bug3017880Test extends \PHPUnit_Framework_TestCase
34 {
35     function testThisDoesNotWorkAsExpected()
36     {
37         $filename = dirname(__FILE__) . '/images/bug3017880.jpg';
38         try {
39             $exif = null;
40             $success = 1; // return true by default, as this function may not resave the file, but it's still success
41             $resave_file = 0;
42             $jpeg = new PelJpeg($filename);
43
44             // should all exif data on photo be cleared (gd and iu will always strip it anyway, so only
45             // force strip if you know the image you're branding is an original)
46             // $jpeg->clearExif();
47
48             if ($exif === null) {
49                 $exif = new PelExif();
50                 $jpeg->setExif($exif);
51                 $tiff = new PelTiff();
52                 $exif->setTiff($tiff);
53             }
54
55             $tiff = $exif->getTiff();
56             $ifd0 = $tiff->getIfd();
57             if ($ifd0 === null) {
58                 $ifd0 = new PelIfd(PelIfd::IFD0);
59                 $tiff->setIfd($ifd0);
60             }
61
62             $software_name = 'Example V2';
63             $software = $ifd0->getEntry(PelTag::SOFTWARE);
64
65             if ($software === null) {
66                 $software = new PelEntryAscii(PelTag::SOFTWARE, $software_name);
67                 $ifd0->addEntry($software);
68                 $resave_file = 1;
69             } else {
70                 $software->setValue($software_name);
71                 $resave_file = 1;
72             }
73
74             if ($resave_file == 1 && ! file_put_contents($filename, $jpeg->getBytes())) {
75                 // if it was okay to resave the file, but it did not save correctly
76             }
77         } catch (Exception $e) {
78             $this->fail('Test should not throw an exception');
79         }
80     }
81 }