Ejemplo n.º 1
0
function get_spec_gif_anmation($url, $width, $height)
{
    require_once APP_ROOT_PATH . "system/utils/gif_encoder.php";
    require_once APP_ROOT_PATH . "system/utils/gif_reader.php";
    require_once APP_ROOT_PATH . "system/utils/es_imagecls.php";
    $gif = new GIFReader();
    $gif->load($url);
    $imagec = new es_imagecls();
    foreach ($gif->IMGS['frames'] as $k => $img) {
        $im = imagecreatefromstring($gif->getgif($k));
        $im = $imagec->make_thumb($im, $img['FrameWidth'], $img['FrameHeight'], "gif", $width, $height, $gen = 1);
        ob_start();
        imagegif($im);
        $content = ob_get_contents();
        ob_end_clean();
        $frames[] = $content;
        $framed[] = $img['frameDelay'];
    }
    $gif_maker = new GIFEncoder($frames, $framed, 0, 2, 0, 0, 0, "bin");
    return $gif_maker->GetAnimation();
}
Ejemplo n.º 2
0
 public function water($source, $water, $alpha = 80, $position = "0")
 {
     //检查文件是否存在
     if (!file_exists($source) || !file_exists($water)) {
         return false;
     }
     //图片信息
     $sInfo = es_imagecls::getImageInfo($source);
     $wInfo = es_imagecls::getImageInfo($water);
     //如果图片小于水印图片,不生成图片
     if ($sInfo["0"] < $wInfo["0"] || $sInfo['1'] < $wInfo['1']) {
         return false;
     }
     if (is_animated_gif($source)) {
         require_once APP_ROOT_PATH . "system/utils/gif_encoder.php";
         require_once APP_ROOT_PATH . "system/utils/gif_reader.php";
         $gif = new GIFReader();
         $gif->load($source);
         foreach ($gif->IMGS['frames'] as $k => $img) {
             $im = imagecreatefromstring($gif->getgif($k));
             //为im加水印
             $sImage = $im;
             $wCreateFun = "imagecreatefrom" . $wInfo['type'];
             if (!function_exists($wCreateFun)) {
                 $wCreateFun = 'imagecreatefromjpeg';
             }
             $wImage = $wCreateFun($water);
             //设定图像的混色模式
             imagealphablending($wImage, true);
             switch (intval($position)) {
                 case 0:
                     break;
                     //左上
                 //左上
                 case 1:
                     $posY = 0;
                     $posX = 0;
                     //生成混合图像
                     imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo[0], $wInfo[1], $alpha);
                     break;
                     //右上
                 //右上
                 case 2:
                     $posY = 0;
                     $posX = $sInfo[0] - $wInfo[0];
                     //生成混合图像
                     imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo[0], $wInfo[1], $alpha);
                     break;
                     //左下
                 //左下
                 case 3:
                     $posY = $sInfo[1] - $wInfo[1];
                     $posX = 0;
                     //生成混合图像
                     imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo[0], $wInfo[1], $alpha);
                     break;
                     //右下
                 //右下
                 case 4:
                     $posY = $sInfo[1] - $wInfo[1];
                     $posX = $sInfo[0] - $wInfo[0];
                     //生成混合图像
                     imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo[0], $wInfo[1], $alpha);
                     break;
                     //居中
                 //居中
                 case 5:
                     $posY = $sInfo[1] / 2 - $wInfo[1] / 2;
                     $posX = $sInfo[0] / 2 - $wInfo[0] / 2;
                     //生成混合图像
                     imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo[0], $wInfo[1], $alpha);
                     break;
             }
             //end im加水印
             ob_start();
             imagegif($sImage);
             $content = ob_get_contents();
             ob_end_clean();
             $frames[] = $content;
             $framed[] = $img['frameDelay'];
         }
         $gif_maker = new GIFEncoder($frames, $framed, 0, 2, 0, 0, 0, "bin");
         $image_rs = $gif_maker->GetAnimation();
         //如果没有给出保存文件名,默认为原图像名
         @unlink($source);
         //保存图像
         file_put_contents($source, $image_rs);
         return true;
     }
     //建立图像
     $sCreateFun = "imagecreatefrom" . $sInfo['type'];
     if (!function_exists($sCreateFun)) {
         $sCreateFun = 'imagecreatefromjpeg';
     }
     $sImage = $sCreateFun($source);
     $wCreateFun = "imagecreatefrom" . $wInfo['type'];
     if (!function_exists($wCreateFun)) {
         $wCreateFun = 'imagecreatefromjpeg';
     }
     $wImage = $wCreateFun($water);
     //设定图像的混色模式
     imagealphablending($wImage, true);
     switch (intval($position)) {
         case 0:
             break;
             //左上
         //左上
         case 1:
             $posY = 0;
             $posX = 0;
             //生成混合图像
             imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo[0], $wInfo[1], $alpha);
             break;
             //右上
         //右上
         case 2:
             $posY = 0;
             $posX = $sInfo[0] - $wInfo[0];
             //生成混合图像
             imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo[0], $wInfo[1], $alpha);
             break;
             //左下
         //左下
         case 3:
             $posY = $sInfo[1] - $wInfo[1];
             $posX = 0;
             //生成混合图像
             imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo[0], $wInfo[1], $alpha);
             break;
             //右下
         //右下
         case 4:
             $posY = $sInfo[1] - $wInfo[1];
             $posX = $sInfo[0] - $wInfo[0];
             //生成混合图像
             imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo[0], $wInfo[1], $alpha);
             break;
             //居中
         //居中
         case 5:
             $posY = $sInfo[1] / 2 - $wInfo[1] / 2;
             $posX = $sInfo[0] / 2 - $wInfo[0] / 2;
             //生成混合图像
             imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo[0], $wInfo[1], $alpha);
             break;
     }
     //如果没有给出保存文件名,默认为原图像名
     @unlink($source);
     //保存图像
     imagejpeg($sImage, $source, 100);
     imagedestroy($sImage);
 }