Example #1
0
 /**
  * 构造函数.
  * 初始化 GIF 图像.
  * 
  * @access public
  * @param string $gifPath GIF 图片文件路径.
  * @return void
  */
 public function __construct($gifPath = NULL)
 {
     if (NULL === $gifPath) {
         return;
     }
     $contents = file_get_contents($gifPath);
     $gifDecoder = new GIFDecoder($contents);
     $this->_frames = $gifDecoder->GIFGetFrames();
     $this->_delays = $gifDecoder->GIFGetDelays();
 }
Example #2
0
 public function __construct($src = NULL, $mod = "url")
 {
     if (!is_null($src)) {
         if ("url" == $mod && is_file($src)) {
             $src = file_get_contents($src);
         }
         try {
             $de = new GIFDecoder($src);
             $this->frames = $de->GIFGetFrames();
             $this->delays = $de->GIFGetDelays();
         } catch (Exception $e) {
             throw new Exception("½âÂëGIFͼƬ³ö´í");
         }
     }
 }
Example #3
0
 /**
  * 构造方法,用于解码GIF图片
  * @param string $src GIF图片数据
  * @param string $mod 图片数据类型
  */
 public function __construct($src = null, $mod = 'url')
 {
     if (!is_null($src)) {
         if ('url' == $mod && is_file($src)) {
             $src = file_get_contents($src);
         }
         /* 解码GIF图片 */
         try {
             $de = new GIFDecoder($src);
             $this->frames = $de->GIFGetFrames();
             $this->delays = $de->GIFGetDelays();
         } catch (Exception $e) {
             throw new Exception("解码GIF图片出错");
         }
     }
 }
Example #4
0
 function GIFReadDescriptor()
 {
     $GIF_screen = array();
     GIFDecoder::GIFGetByte(9);
     $GIF_screen = $this->GIF_buffer;
     $GIF_colorF = $this->GIF_buffer[8] & 0x80 ? 1 : 0;
     if ($GIF_colorF) {
         $GIF_code = $this->GIF_buffer[8] & 0x7;
         $GIF_sort = $this->GIF_buffer[8] & 0x20 ? 1 : 0;
     } else {
         $GIF_code = $this->GIF_colorC;
         $GIF_sort = $this->GIF_sorted;
     }
     $GIF_size = 2 << $GIF_code;
     $this->GIF_screen[4] &= 0x70;
     $this->GIF_screen[4] |= 0x80;
     $this->GIF_screen[4] |= $GIF_code;
     if ($GIF_sort) {
         $this->GIF_screen[4] |= 0x8;
     }
     $this->GIF_string = "GIF87a";
     GIFDecoder::GIFPutByte($this->GIF_screen);
     if ($GIF_colorF == 1) {
         GIFDecoder::GIFGetByte(3 * $GIF_size);
         GIFDecoder::GIFPutByte($this->GIF_buffer);
     } else {
         GIFDecoder::GIFPutByte($this->GIF_global);
     }
     $this->GIF_string .= chr(0x2c);
     $GIF_screen[8] &= 0x40;
     GIFDecoder::GIFPutByte($GIF_screen);
     GIFDecoder::GIFGetByte(1);
     GIFDecoder::GIFPutByte($this->GIF_buffer);
     for (;;) {
         GIFDecoder::GIFGetByte(1);
         GIFDecoder::GIFPutByte($this->GIF_buffer);
         if (($u = $this->GIF_buffer[0]) == 0x0) {
             break;
         }
         GIFDecoder::GIFGetByte($u);
         GIFDecoder::GIFPutByte($this->GIF_buffer);
     }
     $this->GIF_string .= chr(0x3b);
     /*
        Add frames into $GIF_stream array...
     */
     $this->GIF_arrays[] = $this->GIF_string;
 }
Example #5
0
 function updateIcon($uid)
 {
     global $atc_attachment_name, $db_ifftp;
     $uid = intval($uid);
     if ($uid < 1 || !S::isArray($_FILES)) {
         return $this->buildResponse(USER_INVALID_PARAMS);
     }
     ACloud_Sys_Core_Common::setGlobal('customized_current_uid', $uid);
     $user = $this->getCurrentUser();
     if (!$user->isLogin()) {
         return $this->buildResponse(USER_NOT_LOGIN);
     }
     $ext = strtolower(substr(strrchr($_FILES['icon']['name'], '.'), 1));
     L::loadClass('faceupload', 'upload', false);
     $face = new FaceUpload($user->uid);
     $icondb = PwUpload::upload($face);
     require_once R_P . 'require/showimg.php';
     $udir = str_pad(substr($user->uid, -2), 2, '0', STR_PAD_LEFT);
     if (!in_array(strtolower($ext), array('gif', 'jpg', 'jpeg', 'png', 'bmp'))) {
         return $this->buildResponse(USER_UPLOAD_CONTENT_ERROR);
     }
     $filename = "{$user->uid}.{$ext}";
     $sourceFilename = "{$user->uid}_tmp.{$ext}";
     $sourceDir = "upload/{$udir}/";
     $middleDir = "upload/middle/{$udir}/";
     $smallDir = "upload/small/{$udir}/";
     $img_w = $img_h = 0;
     $sourceFile = PwUpload::savePath($db_ifftp, $sourceFilename, $sourceDir);
     $middleFile = PwUpload::savePath($db_ifftp, $filename, $middleDir);
     PwUpload::createFolder(dirname($middleFile));
     PwUpload::movefile($sourceFile, $middleFile);
     require_once R_P . 'require/imgfunc.php';
     if (!($img_size = GetImgSize($middleFile))) {
         P_unlink($middleFile);
         return $this->buildResponse(USER_UPLOAD_CONTENT_ERROR);
     }
     list($img_w, $img_h) = getimagesize($middleFile);
     $smallFile = PwUpload::savePath($db_ifftp, $filename, $smallDir);
     $s_ifthumb = 0;
     PwUpload::createFolder(dirname($smallFile));
     if ($ext == 'gif') {
         L::loadClass('gifdecoder', 'utility', false);
         L::loadClass('gif', 'utility', false);
         $gifDecoder = new GIFDecoder($data);
         $frames = $gifDecoder->GIFGetFrames();
         if (!empty($frames)) {
             foreach ($frames as $key => $value) {
                 $frames[$key] = makeAvatarGifThumb($value, $img_w, $img_h, 48, 48);
             }
             $anime = new GIFEncoder($frames, $gifDecoder->GIFGetDelays(), $gifDecoder->GIFGetLoop(), $gifDecoder->GIFGetDisposal(), $gifDecoder->GIFGetTransparentR(), $gifDecoder->GIFGetTransparentG(), $gifDecoder->GIFGetTransparentB(), 'bin');
             $newGifData = $anime->getAnimation();
             PwUpload::createFolder(dirname($smallFile));
             writeover($smallFile, $newGifData);
             $s_ifthumb = 1;
         }
     } elseif (MakeThumb($middleFile, $smallFile, 48, 48)) {
         $s_ifthumb = 1;
     }
     if ($db_ifftp) {
         PwUpload::movetoftp($middleFile, $middleDir . $filename);
         $s_ifthumb && PwUpload::movetoftp($smallFile, $smallDir . $filename);
     }
     $user_a = explode('|', $user->icon);
     $user_a[2] = $img_w;
     $user_a[3] = $img_h;
     $usericon = setIcon("{$udir}/{$user->uid}.{$ext}", 3, $user_a);
     $userService = L::loadClass('UserService', 'user');
     /* @var $userService PW_UserService */
     $userService->update($user->uid, array('icon' => $usericon));
     list($iconurl) = showfacedesign($usericon, 1, 's');
     return $this->buildResponse(0, array('icon' => $iconurl));
 }
Example #6
0
 private function imagecreatefrom_gif($src)
 {
     if ($this->ani_allow && ($this->ani_gif = $this->is_ani($src))) {
         $gif = new GIFDecoder(file_get_contents($src));
         $img = $gif->GIFGetFrames();
         foreach ($img as $k => $frame) {
             $img[$k] = imagecreatefromstring($frame);
             if ($k === 0) {
                 $img_sizex = imagesx($img[$k]);
                 $img_sizey = imagesy($img[$k]);
             } elseif ($img_sizex != imagesx($img[$k]) || $img_sizey != imagesy($img[$k])) {
                 unset($img);
                 $this->ani_gif = false;
                 $this->ani_offset = null;
                 break;
             }
         }
     }
     if (!$this->ani_gif || count($img) <= 0) {
         $img = imagecreatefromgif($src);
         $this->ani_gif = false;
     } else {
         // set var when 100%
         $this->ani_delays = $gif->GIFGetDelays();
         $this->ani_disposal = $gif->GIFGetDisposal();
         $this->ani_transparent['r'] = $gif->GIFGetTransparentR();
         $this->ani_transparent['g'] = $gif->GIFGetTransparentG();
         $this->ani_transparent['b'] = $gif->GIFGetTransparentB();
     }
     return $img;
 }
Example #7
0
 /*$normalFile = PwUpload::savePath($db_ifftp, "{$winduid}.$ext", "$normalDir");
 		PwUpload::createFolder(dirname($normalFile));
 		list($w, $h) = explode("\t", $db_fthumbsize);
 		if ($db_iffthumb && MakeThumb($source, $normalFile, $w, $h)) {
 			P_unlink($source);
 		} elseif (!PwUpload::movefile($source, $normalFile)) {
 			Showmsg('undefined_action');
 		}*/
 list($img_w, $img_h) = getimagesize($middleFile);
 $smallFile = PwUpload::savePath($db_ifftp, $filename, $smallDir);
 $s_ifthumb = 0;
 PwUpload::createFolder(dirname($smallFile));
 if ($ext == 'gif') {
     L::loadClass('gifdecoder', 'utility', false);
     L::loadClass('gif', 'utility', false);
     $gifDecoder = new GIFDecoder($data);
     $frames = $gifDecoder->GIFGetFrames();
     if (!empty($frames)) {
         foreach ($frames as $key => $value) {
             $frames[$key] = makeAvatarGifThumb($value, $img_w, $img_h, 48, 48);
         }
         $anime = new GIFEncoder($frames, $gifDecoder->GIFGetDelays(), $gifDecoder->GIFGetLoop(), $gifDecoder->GIFGetDisposal(), $gifDecoder->GIFGetTransparentR(), $gifDecoder->GIFGetTransparentG(), $gifDecoder->GIFGetTransparentB(), 'bin');
         $newGifData = $anime->getAnimation();
         PwUpload::createFolder(dirname($smallFile));
         pwCache::writeover($smallFile, $newGifData);
         $s_ifthumb = 1;
     }
 } elseif (MakeThumb($middleFile, $smallFile, 48, 48)) {
     $s_ifthumb = 1;
 }
 if ($db_ifftp) {
Example #8
0
 function GIFReadDescriptor()
 {
     $GIF_screen = array();
     GIFDecoder::GIFGetByte(9);
     $GIF_screen = $this->GIF_buffer;
     $GIF_colorF = $this->GIF_buffer[8] & 0x80 ? 1 : 0;
     if ($GIF_colorF) {
         $GIF_code = $this->GIF_buffer[8] & 0x7;
         $GIF_sort = $this->GIF_buffer[8] & 0x20 ? 1 : 0;
     } else {
         $GIF_code = $this->GIF_colorC;
         $GIF_sort = $this->GIF_sorted;
     }
     $GIF_size = 2 << $GIF_code;
     $this->GIF_screen[4] &= 0x70;
     $this->GIF_screen[4] |= 0x80;
     $this->GIF_screen[4] |= $GIF_code;
     if ($GIF_sort) {
         $this->GIF_screen[4] |= 0x8;
     }
     /* 
      * 
      * GIF Data Begin 
      * 
      */
     if ($this->GIF_TransparentI) {
         $this->GIF_string = "GIF89a";
     } else {
         $this->GIF_string = "GIF87a";
     }
     GIFDecoder::GIFPutByte($this->GIF_screen);
     if ($GIF_colorF == 1) {
         GIFDecoder::GIFGetByte(3 * $GIF_size);
         if ($this->GIF_TransparentI) {
             $this->GIF_TransparentR = $this->GIF_buffer[3 * $this->GIF_TransparentI + 0];
             $this->GIF_TransparentG = $this->GIF_buffer[3 * $this->GIF_TransparentI + 1];
             $this->GIF_TransparentB = $this->GIF_buffer[3 * $this->GIF_TransparentI + 2];
         }
         GIFDecoder::GIFPutByte($this->GIF_buffer);
     } else {
         if ($this->GIF_TransparentI) {
             $this->GIF_TransparentR = $this->GIF_global[3 * $this->GIF_TransparentI + 0];
             $this->GIF_TransparentG = $this->GIF_global[3 * $this->GIF_TransparentI + 1];
             $this->GIF_TransparentB = $this->GIF_global[3 * $this->GIF_TransparentI + 2];
         }
         GIFDecoder::GIFPutByte($this->GIF_global);
     }
     if ($this->GIF_TransparentI) {
         $this->GIF_string .= "!ù" . chr($this->GIF_TransparentI) . "";
     }
     $this->GIF_string .= chr(0x2c);
     $GIF_screen[8] &= 0x40;
     GIFDecoder::GIFPutByte($GIF_screen);
     GIFDecoder::GIFGetByte(1);
     GIFDecoder::GIFPutByte($this->GIF_buffer);
     for (;;) {
         GIFDecoder::GIFGetByte(1);
         GIFDecoder::GIFPutByte($this->GIF_buffer);
         if (($u = $this->GIF_buffer[0]) == 0x0) {
             break;
         }
         GIFDecoder::GIFGetByte($u);
         GIFDecoder::GIFPutByte($this->GIF_buffer);
     }
     $this->GIF_string .= chr(0x3b);
     /* 
      * 
      * GIF Data End 
      * 
      */
     $this->GIF_arrays[] = $this->GIF_string;
 }
Example #9
0
 public function parse($file)
 {
     $content = fread(fopen($file, 'rb'), filesize($file));
     $decoder = new GIFDecoder($content);
     return array('frames' => $decoder->GIFGetFrames(), 'dly' => $decoder->GIFGetDelays(), 'lop' => $decoder->GIFGetLoop(), 'dis' => $decoder->GIFGetDisposal(), 'red' => $decoder->GIFGetTransparentR(), 'grn' => $decoder->GIFGetTransparentG(), 'bln' => $decoder->GIFGetTransparentB());
 }
Example #10
0
 /**
  * Resize the animated gif's by splitting it to frames, and resizing each frame.
  * @param $width
  * @param $height
  * @param $newfile
  * @return array
  */
 function _resizeAnimatedGif($width, $height, $newfile = NULL)
 {
     // jimport('joomla.filesystem.file');
     $libDir = JPATH_ROOT . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'mint' . DIRECTORY_SEPARATOR . 'image_processing';
     require_once $libDir . DIRECTORY_SEPARATOR . 'GIFDecoder.class.php';
     require_once $libDir . DIRECTORY_SEPARATOR . 'GIFEncoder.class.php';
     // Create gif decoder.
     // $gifDecoder = new GIFDecoder(JFile::read($this->imgFile));
     $gifDecoder = new GIFDecoder(file_get_contents($this->imgFile));
     // Write the frames to disk.
     $files = array();
     foreach ($gifDecoder->GIFGetFrames() as $k => $frame) {
         // store the current frame to disk.
         // $filename = JPath::clean($this->tempDir. DIRECTORY_SEPARATOR .uniqid('resize_', true));
         $img = imagecreatefromstring($frame);
         $newimg = @imagecreatetruecolor($width, $height);
         if ($this->transparentGif) {
             $colorcount = imagecolorstotal($img);
             if ($colorcount == 0) {
                 $colorcount = 256;
             }
             imagetruecolortopalette($newimg, true, $colorcount);
             imagepalettecopy($newimg, $img);
             $transparentcolor = imagecolortransparent($img);
             imagefill($newimg, 0, 0, $transparentcolor);
             imagecolortransparent($newimg, $transparentcolor);
         }
         @imagecopyresampled($newimg, $img, 0, 0, 0, 0, $width, $height, $this->imgWidth, $this->imgHeight);
         // take care about border :)
         if (is_resource($this->_border)) {
             @imagecopyresampled($newimg, $this->_border, 0, 0, 0, 0, $width, $height, imagesx($this->_border), imagesy($this->_border));
         }
         ob_start();
         imagegif($newimg);
         $files[] = ob_get_clean();
         // free some memory
         @imagedestroy($newimg);
         @imagedestroy($img);
         unset($frame);
         unset($gifDecoder->GIF_arrays[$k]);
     }
     // Create encoder
     $gifEncoder = new GIFEncoder($files, $gifDecoder->GIFGetDelays(), $gifDecoder->GIFGetLoop(), $gifDecoder->GIFGetDisposal(), $gifDecoder->GIFGetTransparentR(), $gifDecoder->GIFGetTransparentG(), $gifDecoder->GIFGetTransparentB(), 'bin');
     unset($gifDecoder);
     foreach ($files as $f) {
         @unlink($f);
     }
     if (!empty($newfile)) {
         //JFile::write($newfile, $gifEncoder->getAnimation());
         file_put_contents($newfile, $gifEncoder->getAnimation());
     } else {
         @header("Content-type: image/gif");
         echo $gifEncoder->getAnimation();
     }
 }