Skip to content

Commit

Permalink
PSR code reformatting, invalid path warning fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitri ponomarjov committed Jun 21, 2017
1 parent 0322f33 commit c8128b0
Showing 1 changed file with 48 additions and 47 deletions.
95 changes: 48 additions & 47 deletions src/GifCreator/GifCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function create($frames = array(), $durations = array(), $loop = 0)
{
if (!is_array($frames) && !is_array($durations)) {

throw new \Exception($this->version.': '.$this->errors['ERR00']);
throw new \Exception($this->version . ': ' . $this->errors['ERR00']);
}

$this->loop = ($loop > -1) ? $loop : 0;
Expand All @@ -105,7 +105,7 @@ public function create($frames = array(), $durations = array(), $loop = 0)

} elseif (is_string($frames[$i])) { // File path or URL or Binary source code

if (file_exists($frames[$i]) || filter_var($frames[$i], FILTER_VALIDATE_URL)) { // File path
if ((substr($frames[$i], 0, 4) != 'GIF8') && file_exists($frames[$i]) || filter_var($frames[$i], FILTER_VALIDATE_URL)) { // File path

$frames[$i] = file_get_contents($frames[$i]);
}
Expand All @@ -119,7 +119,7 @@ public function create($frames = array(), $durations = array(), $loop = 0)

} else { // Fail

throw new \Exception($this->version.': '.$this->errors['ERR02']);//.' ('.$mode.')'?
throw new \Exception($this->version . ': ' . $this->errors['ERR02']);//.' ('.$mode.')'?
}

if ($i == 0) {
Expand All @@ -129,26 +129,26 @@ public function create($frames = array(), $durations = array(), $loop = 0)

if (substr($this->frameSources[$i], 0, 6) != 'GIF87a' && substr($this->frameSources[$i], 0, 6) != 'GIF89a') {

throw new \Exception($this->version.': '.$i.' '.$this->errors['ERR01']);
throw new \Exception($this->version . ': ' . $i . ' ' . $this->errors['ERR01']);
}

for ($j = (13 + 3 * (2 << (ord($this->frameSources[$i] { 10 }) & 0x07))), $k = TRUE; $k; $j++) {
for ($j = (13 + 3 * (2 << (ord($this->frameSources[$i]{10}) & 0x07))), $k = true; $k; $j++) {

switch ($this->frameSources[$i] { $j }) {
switch ($this->frameSources[$i]{$j}) {

case '!':

if ((substr($this->frameSources[$i], ($j + 3), 8)) == 'NETSCAPE') {

throw new \Exception($this->version.': '.$this->errors['ERR03'].' ('.($i + 1).' source).');
throw new \Exception($this->version . ': ' . $this->errors['ERR03'] . ' (' . ($i + 1) . ' source).');
}

break;
break;

case ';':

$k = false;
break;
break;
}
}

Expand Down Expand Up @@ -185,18 +185,18 @@ public function create($frames = array(), $durations = array(), $loop = 0)
*/
public function gifAddHeader()
{
if (ord($this->frameSources[0] { 10 }) & 0x80) {
if (ord($this->frameSources[0]{10}) & 0x80) {

$cmap = 3 * (2 << (ord($this->frameSources[0] { 10 }) & 0x07));
$cmap = 3 * (2 << (ord($this->frameSources[0]{10}) & 0x07));

$this->gif .= substr($this->frameSources[0], 6, 7);
$this->gif .= substr($this->frameSources[0], 13, $cmap);
if ($this->loop != 1) {
// Browsers interpret loop count differently, but for loop == 1
// we can work around this by excluding loop count completely
// since all browsers seem to handle "no loop count" as
// "play once only".
$this->gif .= "!\377\13NETSCAPE2.0\3\1".$this->encodeAsciiToChar($this->loop)."\0";
// Browsers interpret loop count differently, but for loop == 1
// we can work around this by excluding loop count completely
// since all browsers seem to handle "no loop count" as
// "play once only".
$this->gif .= "!\377\13NETSCAPE2.0\3\1" . $this->encodeAsciiToChar($this->loop) . "\0";
}
}
}
Expand All @@ -209,81 +209,81 @@ public function gifAddHeader()
*/
public function addGifFrames($i, $d)
{
$Locals_str = 13 + 3 * (2 << (ord($this->frameSources[ $i ] { 10 }) & 0x07));
$Locals_str = 13 + 3 * (2 << (ord($this->frameSources[$i]{10}) & 0x07));

$Locals_end = strlen($this->frameSources[$i]) - $Locals_str - 1;
$Locals_tmp = substr($this->frameSources[$i], $Locals_str, $Locals_end);

$Global_len = 2 << (ord($this->frameSources[0 ] { 10 }) & 0x07);
$Locals_len = 2 << (ord($this->frameSources[$i] { 10 }) & 0x07);
$Global_len = 2 << (ord($this->frameSources[0]{10}) & 0x07);
$Locals_len = 2 << (ord($this->frameSources[$i]{10}) & 0x07);

$Global_rgb = substr($this->frameSources[0], 13, 3 * (2 << (ord($this->frameSources[0] { 10 }) & 0x07)));
$Locals_rgb = substr($this->frameSources[$i], 13, 3 * (2 << (ord($this->frameSources[$i] { 10 }) & 0x07)));
$Global_rgb = substr($this->frameSources[0], 13, 3 * (2 << (ord($this->frameSources[0]{10}) & 0x07)));
$Locals_rgb = substr($this->frameSources[$i], 13, 3 * (2 << (ord($this->frameSources[$i]{10}) & 0x07)));

$Locals_ext = "!\xF9\x04".chr(($this->dis << 2) + 0).chr(($d >> 0 ) & 0xFF).chr(($d >> 8) & 0xFF)."\x0\x0";
$Locals_ext = "!\xF9\x04" . chr(($this->dis << 2) + 0) . chr(($d >> 0) & 0xFF) . chr(($d >> 8) & 0xFF) . "\x0\x0";

if ($this->colour > -1 && ord($this->frameSources[$i] { 10 }) & 0x80) {
if ($this->colour > -1 && ord($this->frameSources[$i]{10}) & 0x80) {

for ($j = 0; $j < (2 << (ord($this->frameSources[$i] { 10 } ) & 0x07)); $j++) {
for ($j = 0; $j < (2 << (ord($this->frameSources[$i]{10}) & 0x07)); $j++) {

if (ord($Locals_rgb { 3 * $j + 0 }) == (($this->colour >> 16) & 0xFF) &&
ord($Locals_rgb { 3 * $j + 1 }) == (($this->colour >> 8) & 0xFF) &&
ord($Locals_rgb { 3 * $j + 2 }) == (($this->colour >> 0) & 0xFF)
if (ord($Locals_rgb{3 * $j + 0}) == (($this->colour >> 16) & 0xFF) &&
ord($Locals_rgb{3 * $j + 1}) == (($this->colour >> 8) & 0xFF) &&
ord($Locals_rgb{3 * $j + 2}) == (($this->colour >> 0) & 0xFF)
) {
$Locals_ext = "!\xF9\x04".chr(($this->dis << 2) + 1).chr(($d >> 0) & 0xFF).chr(($d >> 8) & 0xFF).chr($j)."\x0";
$Locals_ext = "!\xF9\x04" . chr(($this->dis << 2) + 1) . chr(($d >> 0) & 0xFF) . chr(($d >> 8) & 0xFF) . chr($j) . "\x0";
break;
}
}
}
$Locals_img = '';

switch ($Locals_tmp { 0 }) {
switch ($Locals_tmp{0}) {

case '!':

$Locals_img = substr($Locals_tmp, 8, 10);
$Locals_tmp = substr($Locals_tmp, 18, strlen($Locals_tmp) - 18);

break;
break;

case ',':

$Locals_img = substr($Locals_tmp, 0, 10);
$Locals_tmp = substr($Locals_tmp, 10, strlen($Locals_tmp) - 10);

break;
break;
}
if (ord($this->frameSources[$i] { 10 }) & 0x80 && $this->imgBuilt) {
if (ord($this->frameSources[$i]{10}) & 0x80 && $this->imgBuilt) {

if ($Global_len == $Locals_len) {

if ($this->gifBlockCompare($Global_rgb, $Locals_rgb, $Global_len)) {

$this->gif .= $Locals_ext.$Locals_img.$Locals_tmp;
$this->gif .= $Locals_ext . $Locals_img . $Locals_tmp;

} else {

$byte = ord($Locals_img { 9 });
$byte = ord($Locals_img{9});
$byte |= 0x80;
$byte &= 0xF8;
$byte |= (ord($this->frameSources[0] { 10 }) & 0x07);
$Locals_img { 9 } = chr($byte);
$this->gif .= $Locals_ext.$Locals_img.$Locals_rgb.$Locals_tmp;
$byte |= (ord($this->frameSources[0]{10}) & 0x07);
$Locals_img{9} = chr($byte);
$this->gif .= $Locals_ext . $Locals_img . $Locals_rgb . $Locals_tmp;
}

} else {

$byte = ord($Locals_img { 9 });
$byte = ord($Locals_img{9});
$byte |= 0x80;
$byte &= 0xF8;
$byte |= (ord($this->frameSources[$i] { 10 }) & 0x07);
$Locals_img { 9 } = chr($byte);
$this->gif .= $Locals_ext.$Locals_img.$Locals_rgb.$Locals_tmp;
$byte |= (ord($this->frameSources[$i]{10}) & 0x07);
$Locals_img{9} = chr($byte);
$this->gif .= $Locals_ext . $Locals_img . $Locals_rgb . $Locals_tmp;
}

} else {

$this->gif .= $Locals_ext.$Locals_img.$Locals_tmp;
$this->gif .= $Locals_ext . $Locals_img . $Locals_tmp;
}

$this->imgBuilt = true;
Expand All @@ -310,9 +310,10 @@ public function gifBlockCompare($globalBlock, $localBlock, $length)
{
for ($i = 0; $i < $length; $i++) {

if ($globalBlock { 3 * $i + 0 } != $localBlock { 3 * $i + 0 } ||
$globalBlock { 3 * $i + 1 } != $localBlock { 3 * $i + 1 } ||
$globalBlock { 3 * $i + 2 } != $localBlock { 3 * $i + 2 }) {
if ($globalBlock{3 * $i + 0} != $localBlock{3 * $i + 0} ||
$globalBlock{3 * $i + 1} != $localBlock{3 * $i + 1} ||
$globalBlock{3 * $i + 2} != $localBlock{3 * $i + 2}
) {

return 0;
}
Expand All @@ -331,15 +332,15 @@ public function gifBlockCompare($globalBlock, $localBlock, $length)
*/
public function encodeAsciiToChar($char)
{
return (chr($char & 0xFF).chr(($char >> 8) & 0xFF));
return (chr($char & 0xFF) . chr(($char >> 8) & 0xFF));
}

/**
* Reset and clean the current object
*/
public function reset()
{
$this->frameSources=[];
$this->frameSources = [];
$this->gif = 'GIF89a'; // the GIF header
$this->imgBuilt = false;
$this->loop = 0;
Expand Down

0 comments on commit c8128b0

Please sign in to comment.