示例#1
0
 public function spriteDirRecur($dir)
 {
     $nbr = countSubDir($dir);
     if (is_dir($dir)) {
         if ($dh = opendir($dir)) {
             while (($file = readdir($dh)) != FALSE) {
                 if ($file != '.' && $file != '..') {
                     if (is_dir($dir . '/' . $file)) {
                         $this->spriteDirRecur($dir . '/' . $file);
                         $this->ib++;
                     }
                     if (is_png($dir . '/' . $file)) {
                         $this->png_file[] = imagecreatefrompng($dir . '/' . $file);
                     }
                 }
             }
             closedir($dh);
         }
     }
     if ($this->ib == $this->nbr) {
         if (!empty($this->padding)) {
             $this->spriteToPngPadding($this->png_file, $this->png_name);
         } else {
             $this->spriteToPng($this->png_file, $this->png_name);
         }
     }
 }
    $arr = unpack("c*", $length_bin);
    $length = 0;
    for ($i = 1; $i <= 4; $i++) {
        $length += pow(256, 4 - $i) * $arr[$i];
    }
    return $length + 12;
}
function next_chunk($binary, $chunk_head_position)
{
    return $chunk_head_position + get_chunk_length($binary, $chunk_head_position);
}
function is_animated($binary, $length)
{
    $chunk_head_position = 8;
    while ($chunk_head_position < $length) {
        if (chunk_type_compare($binary, "IDAT", $chunk_head_position)) {
            return false;
        }
        if (chunk_type_compare($binary, "acTL", $chunk_head_position)) {
            return true;
        }
        $chunk_head_position = next_chunk($binary, $chunk_head_position);
    }
    return false;
}
$filename = $argv[1];
$f = fopen($filename, "rb");
$header = fread($f, 1024);
fclose($f);
var_dump(is_png($header) && is_animated($header, 1024));
function make_thumbnail($file)
{
    $image = null;
    if (is_jpg($file["ext"])) {
        $image = imagecreatefromjpeg($file["filepath"]);
    } else {
        if (is_png($file["ext"])) {
            $image = imagecreatefrompng($file["filepath"]);
        }
    }
    if (is_null($image)) {
        return false;
    }
    $org = array("w" => imagesx($image), "h" => imagesy($image));
    $new = null;
    if ($org["w"] < $org["h"] || $org["w"] == $org["h"]) {
        $w = MAXWIDTHTHUMB;
        $rate = $w / $org["w"];
        $new = array("w" => $w, "h" => intval($org["h"] * $rate));
    } else {
        $h = MAXHEIGHTTHUMB;
        $rate = $h / $org["h"];
        $new = array("w" => intval($org["w"] * $rate), "h" => $h);
    }
    $r = false;
    if (USEIMAGEMAGICK) {
        $cmd = "convert ";
        if (is_jpg($file["ext"])) {
            $cmd .= '-define jpeg:size=' . $new["w"] . 'x' . $new["h"];
        }
        $cmd .= ' -resize ' . $new["w"] . 'x' . $new["h"] . ' -quality ' . THUMBQUALITY . ' ' . $file["filepath"] . ' ' . $file["filepath"];
        $r = system($cmd);
        if ($r !== false) {
            $r = true;
        }
    } else {
        $new_image = imagecreatetruecolor($new["w"], $new["h"]);
        $r = imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new["w"], $new["h"], $org["w"], $org["h"]);
        if ($r === false) {
            imagedestroy($new_image);
            return false;
        }
        $r = imagejpeg($new_image, $file["filepath"], THUMBQUALITY);
        imagedestroy($new_image);
    }
    imagedestroy($image);
    return $r;
}
示例#4
0
function type_of_image($file)
{
    if (is_jpg($file)) {
        return 'jpg';
    }
    if (is_png($file)) {
        return 'png';
    }
    if (is_gif($file)) {
        return 'gif';
    }
    return false;
}