This repository has been archived by the owner on Jan 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
1,859 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
tests/output/* | ||
tests/Resources/output | ||
tests/gifs/*.gif | ||
|
||
# Created by .ignore support plugin (hsz.mobi) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
namespace GIFEndec\Tests\Resources; | ||
|
||
class Sample | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $data; | ||
|
||
/** | ||
* Sample constructor. | ||
* @param string $name | ||
* @param array $data | ||
*/ | ||
public function __construct($name, array $data) | ||
{ | ||
$this->name = $name; | ||
$this->data = $data; | ||
} | ||
|
||
public function name() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function url() | ||
{ | ||
return $this->data['url']; | ||
} | ||
|
||
private function localDir() | ||
{ | ||
$dir = __DIR__ . "/output/{$this->name}"; | ||
if (!is_dir($dir)) { | ||
mkdir($dir, null, true); | ||
} | ||
|
||
return $dir; | ||
} | ||
|
||
public function localPath() | ||
{ | ||
return $this->localDir() . "/original.gif"; | ||
} | ||
|
||
public function getFrameRenderedSHA1($index) | ||
{ | ||
return $this->data["frames_rendered_sha1"][$index]; | ||
} | ||
|
||
public function getFrameRawSHA1($index) | ||
{ | ||
return $this->data["frames_raw_sha1"][$index]; | ||
} | ||
|
||
public function emptyRenderedFramesDir() | ||
{ | ||
return $this->openOrClearOutputDir('rendered'); | ||
} | ||
|
||
public function emptyRawFramesDir() | ||
{ | ||
return $this->openOrClearOutputDir('raw'); | ||
} | ||
|
||
public function download() | ||
{ | ||
if (file_exists($this->localPath())) { | ||
return; | ||
} | ||
|
||
$ch = curl_init($this->url()); | ||
$fp = fopen($this->localPath(), 'w'); | ||
curl_setopt($ch, CURLOPT_FILE, $fp); | ||
curl_exec($ch); | ||
curl_close($ch); | ||
fclose($fp); | ||
} | ||
|
||
private function openOrClearOutputDir($type) | ||
{ | ||
$dir = "{$this->localDir()}/$type/"; | ||
$this->createDirOrClear($dir); | ||
return $dir; | ||
} | ||
|
||
private function createDirOrClear($dir) | ||
{ | ||
if (!is_dir($dir)) { | ||
mkdir($dir, null, true); | ||
} else { | ||
foreach (glob("$dir/*") as $file) { | ||
unlink($file); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
namespace GIFEndec\Tests\Resources; | ||
|
||
class SampleCollection | ||
{ | ||
/** | ||
* @var Sample[] | ||
*/ | ||
private $samples = []; | ||
|
||
public function __construct() | ||
{ | ||
$samples = json_decode(file_get_contents(__DIR__ . '/gifs.json'), true); | ||
foreach ($samples as $name => $data) { | ||
if (!$data['enabled']) { | ||
continue; | ||
} | ||
$this->samples[] = new Sample($name, $data); | ||
} | ||
|
||
$this->downloadAll(); | ||
} | ||
|
||
/** | ||
* @return Sample[] | ||
*/ | ||
public function read() | ||
{ | ||
return $this->samples; | ||
} | ||
|
||
private function downloadAll() | ||
{ | ||
foreach ($this->samples as $sample) { | ||
$sample->download(); | ||
} | ||
} | ||
} |
Oops, something went wrong.