File tree Expand file tree Collapse file tree 9 files changed +76
-5
lines changed
Expand file tree Collapse file tree 9 files changed +76
-5
lines changed Original file line number Diff line number Diff line change 1+ # 0.1.1
2+
3+ ## Enhancements
4+
5+ - Load a WMF file from a string in [ #5 ] ( https://github.com/PHPOffice/WMF/pull/5 ) by [ @Progi1984 ] ( https://github/Progi1984 )
6+
7+ ## Bug fixes
8+
9+ - N/A
10+
11+ ## Miscellaneous
12+
13+ - N/A
14+
Original file line number Diff line number Diff line change 4343 - WMF : ' usage/wmf.md'
4444 - Credits : ' credits.md'
4545 - Releases :
46- - ' 0.1.0 (WIP) ' : ' changes/0.1.0.md'
46+ - ' 0.1.1 (WIP) ' : ' changes/0.1.1.md'
47+ - ' 0.1.0 ' : ' changes/0.1.0.md'
4748 - Developers :
4849 - ' Coveralls ' : ' https://coveralls.io/github/PHPOffice/WMF'
4950 - ' Code Coverage ' : ' coverage/index.html'
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ interface ReaderInterface
99{
1010 public function load (string $ filename ): bool ;
1111
12+ public function loadFromString (string $ content ): bool ;
13+
1214 public function save (string $ filename , string $ format ): bool ;
1315
1416 public function getMediaType (): string ;
Original file line number Diff line number Diff line change @@ -72,13 +72,25 @@ public function isWMF(string $filename): bool
7272 return $ key == (int ) 0x9AC6CDD7 ;
7373 }
7474
75- /**
76- * @see https://github.com/affinitybridge/mpdf/blob/master/src/Image/Wmf.php
77- */
7875 public function load (string $ filename ): bool
7976 {
8077 $ this ->content = file_get_contents ($ filename );
8178
79+ return $ this ->loadContent ();
80+ }
81+
82+ public function loadFromString (string $ content ): bool
83+ {
84+ $ this ->content = $ content ;
85+
86+ return $ this ->loadContent ();
87+ }
88+
89+ /**
90+ * @see https://github.com/affinitybridge/mpdf/blob/master/src/Image/Wmf.php
91+ */
92+ private function loadContent (): bool
93+ {
8294 $ this ->pos = 0 ;
8395 $ this ->gdiObjects = [];
8496 $ k = 72 / 25.4 ;
Original file line number Diff line number Diff line change @@ -16,11 +16,21 @@ class Imagick extends ReaderAbstract
1616 protected $ im ;
1717
1818 public function load (string $ filename ): bool
19+ {
20+ return $ this ->loadContent ($ filename , false );
21+ }
22+
23+ public function loadFromString (string $ content ): bool
24+ {
25+ return $ this ->loadContent ($ content , true );
26+ }
27+
28+ private function loadContent (string $ content , bool $ isBlob ): bool
1929 {
2030 try {
2131 $ this ->im = new ImagickBase ();
2232
23- return $ this ->im ->readImage ($ filename );
33+ return $ isBlob ? $ this ->im ->readImageBlob ( $ content ) : $ this -> im -> readImage ($ content );
2434 } catch (ImagickException $ e ) {
2535 $ this ->im ->clear ();
2636
Original file line number Diff line number Diff line change @@ -32,6 +32,11 @@ public function load(string $filename): bool
3232 return $ this ->reader ->load ($ filename );
3333 }
3434
35+ public function loadFromString (string $ content ): bool
36+ {
37+ return $ this ->reader ->loadFromString ($ content );
38+ }
39+
3540 public function save (string $ filename , string $ format ): bool
3641 {
3742 return $ this ->reader ->save ($ filename , $ format );
Original file line number Diff line number Diff line change @@ -20,6 +20,15 @@ public function testLoad(string $file): void
2020 $ this ->assertTrue ($ reader ->load ($ this ->getResourceDir () . $ file ));
2121 }
2222
23+ /**
24+ * @dataProvider dataProviderFilesWMF
25+ */
26+ public function testLoadFromString (string $ file ): void
27+ {
28+ $ reader = new GD ();
29+ $ this ->assertTrue ($ reader ->loadFromString (file_get_contents ($ this ->getResourceDir () . $ file )));
30+ }
31+
2332 /**
2433 * @dataProvider dataProviderFilesWMF
2534 */
Original file line number Diff line number Diff line change @@ -20,6 +20,15 @@ public function testLoad(string $file): void
2020 $ this ->assertTrue ($ reader ->load ($ this ->getResourceDir () . $ file ));
2121 }
2222
23+ /**
24+ * @dataProvider dataProviderFilesWMF
25+ */
26+ public function testLoadFromString (string $ file ): void
27+ {
28+ $ reader = new ImagickReader ();
29+ $ this ->assertTrue ($ reader ->loadFromString (file_get_contents ($ this ->getResourceDir () . $ file )));
30+ }
31+
2332 /**
2433 * @dataProvider dataProviderFilesWMF
2534 */
Original file line number Diff line number Diff line change @@ -18,6 +18,15 @@ public function testLoad(string $file): void
1818 $ this ->assertTrue ($ reader ->load ($ this ->getResourceDir () . $ file ));
1919 }
2020
21+ /**
22+ * @dataProvider dataProviderFilesWMF
23+ */
24+ public function testLoadFromString (string $ file ): void
25+ {
26+ $ reader = new Magic ();
27+ $ this ->assertTrue ($ reader ->loadFromString (file_get_contents ($ this ->getResourceDir () . $ file )));
28+ }
29+
2130 /**
2231 * @dataProvider dataProviderFilesWMF
2332 */
You can’t perform that action at this time.
0 commit comments