public function generate(array $array) { $frames = array(); $frame_delay = array(); foreach ($array['frames'] as $frame) { $image = $this->_createImage($frame['image']); if (array_key_exists('text', $frame)) { foreach ($frame['text'] as $text) { // Set defaults $defaults = array("angle" => $this->_defaultAngle, "fonts" => $this->_defaultFont, "fonts-color" => $this->_defaultFontColor, "fonts-size" => $this->_defaultFontSize, "y-position" => $this->_defaultYPosition, "x-position" => $this->_defaultXPosition, "text" => null, "letter-spacing" => 0); // Overwrite all the defaults with the arguments $args = array_merge($defaults, $text); $fontColor = is_array($args['fonts-color']) ? $args['fonts-color'] : $this->_hex2rgb($args['fonts-color']); $text_color = imagecolorallocate($image, $fontColor[0], $fontColor[1], $fontColor[2]); $this->imagettftextSp($image, $args['fonts-size'], $args['angle'], $args['x-position'], $args['y-position'], $text_color, $args['fonts'], $args['text'], $args['letter-spacing']); } } $delay = array_key_exists('delay', $frame) ? $frame['delay'] : $this->_defaultDelay; ob_start(); imagegif($image); $frames[] = ob_get_contents(); $frame_delay[] = $delay; // Delay in the animation. ob_end_clean(); } $repeat = array_key_exists('repeat', $array) ? $array['repeat'] : $this->_defaultRepeat; $gif = new GIFEncoder($frames, $frame_delay, $repeat, 2, 0, 0, 0, 0, 'bin'); return $gif->GetAnimation(); }
function GetImage() { eval(sprintf('$_SESSION["answer"] = (%d %s %d);', self::$num['rand1'], self::$math[self::$num['op']], self::$num['rand2'])); if ($_SESSION['answer'] < 0) { self::AnimCaptcha(self::$gifs, self::$pause); } $gif = new GIFEncoder(self::$frames, self::$time, 0, 2, 0, 0, 0, "url"); if (!headers_sent()) { header('Content-type:image/gif'); echo $gif->GetAnimation(); } }
function AnimatedOut() { for ($i = 0; $i < ANIM_FRAMES; $i++) { $image = imageCreateTrueColor(imageSX($this->image), imageSY($this->image)); if (imageCopy($image, $this->image, 0, 0, 0, 0, imageSX($this->image), imageSY($this->image))) { Captcha::DoNoise($image, 200, 0); Ob_Start(); imageGif($image); imageDestroy($image); $f_arr[] = Ob_Get_Contents(); $d_arr[] = ANIM_DELAYS; Ob_End_Clean(); } } $GIF = new GIFEncoder($f_arr, $d_arr, 0, 2, -1, -1, -1, 'C_MEMORY'); return $GIF->GetAnimation(); }
/** * Анимация */ public function getAnimation() { if (isset($this->animation)) { return $this->animation; } check_condition($this->IMAGES, 'No images for gif'); PsLibs::inst()->GifEncoder(); $frames = array(); $framed = array(); foreach ($this->IMAGES as $path => $delay) { ob_start(); SimpleImage::inst()->load($path)->output(IMAGETYPE_GIF)->close(); $frames[] = ob_get_contents(); $framed[] = $delay; // Delay in the animation. ob_end_clean(); } // Generate the animated gif and output to screen. $gif = new GIFEncoder($frames, $framed, 0, 2, 0, 0, 0, 'bin'); $this->animation = $gif->GetAnimation(); return $this->animation; }
function resizeImage($file, $dest, $newWidth, $newHeight, $quality, $bResizeOnWidth) { if (!file_exists($file)) { if ($this->debug) { echo 'source does not exist!' . FF_BR; } return false; } $w = 0; $h = 0; $src = false; // Create an Image from it so we can do the resize $info = getimagesize($file); $width = $info[0]; $height = $info[1]; $type = $info[2]; $bits = $info['bits']; // Do not resample up the image size if ($width <= $newWidth && $height <= $newHeight) { copy($file, $dest); return is_file($dest); } if ($type == '1' && $dest != $file) { // if dest != file, then must be orig gif file, not the temp file to be resized $fp = fread(fopen($file, "rb"), filesize($file)); if ($fp) { $gifb = new GIFDecoder($fp); } elseif ($this->debug) { echo 'could not read animated file' . FF_BR; } } // Must eval is GIF has more than one frame. Cannot determine by bit length, as some are 6, some are 8, and some are crazy motherfuckers. if ($type == '1' && is_object($gifb) && sizeof($gifb->GIFGetFrames()) > 1) { $arr = $gifb->GIFGetFrames(); $dly = $gifb->GIFGetDelays(); for ($i = 0; $i < count($arr); $i++) { $name = dirname($dest) . '/temp_' . ($i < 10 ? '00' : ($i < 100 ? '0' : '')) . $i . '.gif'; fwrite(fopen($name, 'wb'), $arr[$i]); if ($this->resizeImage($name, $name, $newWidth, $newHeight, $quality, $bResizeOnWidth)) { list($w, $h) = getimagesize($name); $giff[] = $name; $gifd[] = $dly[$i]; } } $gife = new GIFEncoder($giff, $gifd, 0, 2, 0, 0, 0, 'url'); fwrite(fopen($dest, 'wb'), $gife->GetAnimation()); //for ($i=0; $i<sizeof($giff); $i++) unlink($giff[$i]); $this->resize_count += sizeof($arr) - 1; return is_file($dest); } else { // Do normal resize, whatever that is... switch ($type) { case '2': $src = @imagecreatefromjpeg($file); break; case '3': $src = @imagecreatefrompng($file); break; case '1': $src = @imagecreatefromgif($file); break; } if (!$src) { if ($this->debug) { echo 'problem opening ' . $file . ' - check it is complete' . FF_BR; } return false; } if ($bResizeOnWidth == 1 || $width > $height) { $w = $newWidth; $ratio = $height / $width; $h = round($ratio * $w); } else { $h = $newHeight; $ratio = $width / $height; $w = round($ratio * $h); } if ($tmp = imagecreatetruecolor($w, $h)) { // FROM Author: Tim Eckel - Date: 09/07/07 - Version: 1.1 - Project: FreeRingers.net - Freely distributable if (FF_IMG_QUALITY < 5 && ($w * FF_IMG_QUALITY < $width || $h * FF_IMG_QUALITY < $height)) { if ($tmp2 = imagecreatetruecolor($w * FF_IMG_QUALITY + 1, $h * FF_IMG_QUALITY + 1)) { imagecopyresized($tmp2, $src, 0, 0, 0, 0, $w * FF_IMG_QUALITY + 1, $h * FF_IMG_QUALITY + 1, $width, $height); imagecopyresampled($tmp, $tmp2, 0, 0, 0, 0, $w, $h, $w * FF_IMG_QUALITY, $h * FF_IMG_QUALITY); imagedestroy($tmp2); } elseif ($this->debug) { echo 'could not create temp image for faster resize' . FF_BR; return false; } } else { imagecopyresampled($tmp, $src, 0, 0, 0, 0, $w, $h, $width, $height); } switch ($type) { case '2': @imagejpeg($tmp, $dest, $quality); break; case '3': @imagepng($tmp, $dest, 9 - round($quality / 9)); break; // quality is 0-9, with 0 being the best. convert from jpeg 100 scale. // quality is 0-9, with 0 being the best. convert from jpeg 100 scale. case '1': @imagegif($tmp, $dest); break; // gif has no quality } imagedestroy($src); imagedestroy($tmp); return is_file($dest); // return true if file was created successfully } elseif ($this->debug) { echo 'could not create temp image for resize' . FF_BR; } return false; } }
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); }
int 'Source type' ); */ $gif = new GIFEncoder($frames_preview, $framed_preview, 0, 2, 255, 255, 255, "url"); fwrite(fopen($target3D_preview . '/axZmGifAnimation.gif', "wb"), $gif->GetAnimation()); // Remove preview gif files if ($dh = opendir($target3D_preview)) { $framesArray = array(); while (false !== ($dat = readdir($dh))) { if ($dat != "." && $dat != ".." && $dat != 'axZmGifAnimation.gif') { unlink($target3D_preview . '/' . $dat); } } } $gif = new GIFEncoder($frames_thumb, $framed_thumb, 0, 2, 0, 0, 0, "url"); fwrite(fopen($target3D_thumb . '/axZmGifAnimation.gif', "wb"), $gif->GetAnimation()); // Remove preview gif files if ($dh = opendir($target3D_thumb)) { $framesArray = array(); while (false !== ($dat = readdir($dh))) { if ($dat != "." && $dat != ".." && $dat != 'axZmGifAnimation.gif') { unlink($target3D_thumb . '/' . $dat); } } } $preview360imagePath = str_replace('//', '/', str_replace('\\', '/', dirname($_SERVER['PHP_SELF']) . '/' . $target3D_preview . '/axZmGifAnimation.gif')); $thumb360imagePath = str_replace('//', '/', str_replace('\\', '/', dirname($_SERVER['PHP_SELF']) . '/' . $target3D_thumb . '/axZmGifAnimation.gif')); echo ' jQuery.preview360imagePath = "' . $preview360imagePath . '"; jQuery("#thumb360spin").attr("src", "' . $thumb360imagePath . '"); if (jQuery.spin360Loaded){
function generate() { $this->no_cache(); if (!headers_sent()) { header('Content-type: image/gif'); } else { trigger_error('generate() was called after headers already sent.', E_USER_ERROR); } $this->check(); $image_string = ''; $image_string .= $this->microseconds(); $image_string .= date('r') . mt_rand(1, 1000); $image_string = substr(md5($image_string), 1, $this->string_length); session_start(); $_SESSION[$this->session_name] = $image_string; $filename = array(); $frame_delays = array(); // Define random color, which // constant for each letter in each frame $ar_char_color = array(); $max = count($this->color['text']); for ($i = 0; $i < $this->string_length; $i++) { $index = mt_rand(0, $max - 1); $ar_char_color[] = $this->getRGBCode($this->color['text'][$index]); } // Random background color $ar_grid_color = array(); $max = count($this->color['background']); $index = mt_rand(0, $max - 1); $ar_background_color[] = $this->getRGBCode($this->color['background'][$index]); // Random grid color $ar_grid_color = array(); $max = count($this->color['grid']); $index = mt_rand(0, $max - 1); $ar_grid_color[] = $this->getRGBCode($this->color['grid'][$index]); for ($frame_count = 1; $frame_count <= $this->frame_number; $frame_count++) { // Generate an image for each frame $random_font = $this->random_font(); if ($random_font) { $x = (imagefontwidth($random_font) + 4 + $this->text_space) * $this->string_length; $height = (int) (imagefontheight($random_font) * $this->font_size / 4) + $this->random_y_factor * 2; } else { $x = (imagefontwidth($this->font_size) + $this->text_space) * $this->string_length; $height = imagefontheight($this->font_size) + 10 + $this->random_y_factor * 2; } $width = $x + 20; $image = imagecreate($width, $height); $border_color = imagecolorallocate($image, 0x0, 0x0, 0x0); $background_color = imagecolorallocate($image, $ar_background_color[0][0], $ar_background_color[0][1], $ar_background_color[0][2]); $grid_color = imagecolorallocate($image, $ar_grid_color[0][0], $ar_grid_color[0][1], $ar_grid_color[0][2]); imagefilledrectangle($image, 0, 0, $width, $height, $background_color); for ($i = 0; $i < $this->grid_density; $i++) { if ($this->randomize_grid) { $i_factor = (mt_rand(1, 100) + microtime()) % mt_rand(2, 100); $i_factor++; $i_factor2 = (mt_rand(1, 100) + microtime()) % mt_rand(2, 100); $i_factor2++; } else { $i_factor = 3; $i_factor2 = 3; } imagesetthickness($image, mt_rand(1, 2)); imageline($image, $i * ($width / $i_factor), 2, $i * ($width / $i_factor2), $height, $grid_color); } for ($i = 0; $i < 5; $i++) { if ($this->randomize_grid) { $i_factor = (mt_rand(1, 100) + microtime()) % mt_rand(2, 100); $i_factor++; $i_factor2 = (mt_rand(1, 100) + microtime()) % mt_rand(2, 100); $i_factor2++; } else { $i_factor = 5; $i_factor2 = 5; } imageline($image, 0, $i * ($height / $i_factor), $width, $i * ($height / $i_factor2), $grid_color); } if ($this->randomize_grid) { for ($i = 0; $i < 4; $i++) { imageline($image, 0, $i * ($height / 3), $width, $i * ($height / 3), $grid_color); } } if ($this->draw_ellipse) { // Create random ellipse $comp = $this->get_color_complement($ar_char_color[0], mt_rand(1, 3), mt_rand(1, 3), mt_rand(1, 3)); $ellipse_color = imagecolorallocate($image, $comp[0], $comp[1], $comp[2]); imagefilledellipse($image, mt_rand(20, floor(0.8 * $width)), floor($height / 2), mt_rand(16, 20), mt_rand(23, 30), $ellipse_color); } imagerectangle($image, 0, 0, $width - 1, $height - 1, $border_color); $x = sprintf("%d", ($width - $x) / 2); if ($random_font) { $y = ($height - imagefontheight($random_font)) / 2; } else { $y = ($height - imagefontheight($this->font_size)) / 2; } $offset_x = 0; $x += mt_rand(0, 2); for ($i = 0; $i < $this->string_length; $i++) { $char = substr($image_string, $i, 1); $x2 = $x + $offset_x - 1 + mt_rand(0, 1); $y2 = $y - $this->random_y_factor + mt_rand(0, $this->random_y_factor * 2); $y2 = $y + 10; $foreground_color = imagecolorallocate($image, $ar_char_color[$i][0], $ar_char_color[$i][1], $ar_char_color[$i][2]); if ($random_font) { $angle = $this->random_angle(); // Overlap character if ($this->overlap_text) { $decide = mt_rand(0, 10); // use complement color or original char color ? if ($decide <= 9) { $comp = $this->get_color_complement($ar_char_color[$i], mt_rand(1, 13), mt_rand(1, 13), mt_rand(1, 13)); $comp_color = imagecolorallocate($image, $comp[0], $comp[1], $comp[2]); } else { $comp_color = $foreground_color; } unset($decide); imagettftext($image, $this->font_size, $angle + mt_rand(0, 1), $x2 + $this->random_overlap_factor(), $y2 + $this->random_overlap_factor(), $comp_color, $this->random_font(), $char); } imagettftext($image, $this->font_size, $angle, $x2, $y2, $foreground_color, $this->random_font(), $char); $offset_x += imagefontwidth($random_font) * $this->font_size / 8 + $this->text_space; } else { imagestring($image, $this->font_size, $x2, $y2, $char, $foreground_color); $offset_x += imagefontwidth($this->font_size) + $this->text_space; } } if ($this->frame_number > 1) { // only if frames are greater than 1, // save every frame to a temp file $rand_filename = $this->temp_dir . md5(microtime() . getenv('REMOTE_ADDR')) . mt_rand(1, 999) . '.txt'; $fp = fopen($rand_filename, 'w+'); if ($fp) { flock($fp, 2); fwrite($fp, ''); flock($fp, 3); fclose($fp); imagegif($image, $rand_filename); imagedestroy($image); $filename[] = $rand_filename; $frame_delays[] = $this->frame_delay; unset($rand_filename); } } } if ($this->frame_number == 1) { // Single frame, let's use the simple method imagegif($image); } else { if (count($filename) > 0) { // > 1 frame, merge frames $angif = new GIFEncoder($filename, $frame_delays, 0, 2, 0, 0, 0, 'url'); echo $angif->GetAnimation(); //Remove temp file(s) foreach ($filename as $s) { unlink($s); } unset($filename, $frame_delays); unset($frame_delays); } } }
/** * Displays the finally calculated gif with all life cycles. * * @param int $_numGifFrames Amount of life cycles the gif returned should consists (standard=100). */ public function displayResult($_numGifFrames = 100) { $frames = []; $delayTime = []; for ($x = 0; $x < $_numGifFrames; $x++) { $im = @ImageCreateTrueColor($this->width * 10, $this->height * 10) or die("Kann keinen neuen GD-Bild-Stream erzeugen"); $delayTime[$x] = 5; $background_color = ImageColorAllocate($im, 255, 255, 255); imagefill($im, 0, 0, $background_color); $black = ImageColorAllocate($im, 0, 0, 0); for ($i = 0; $i < $this->height; $i++) { for ($j = 0; $j < $this->width; $j++) { if ($this->gameField->isAlive($i, $j)) { imagefilledrectangle($im, $j * 10, $i * 10, $j * 10 + 10, $i * 10 + 10, $black); } } } ob_start(); imagegif($im); $frames[$x] = ob_get_contents(); ob_end_clean(); imagedestroy($im); $this->calculateNextLifeCycle(); } /* usage external GIF-Encoder: image_stream = new GIFEncoder ( URL or Binary data 'Sources' int 'Delay times' int 'Animation loops' int 'Disposal' int 'Transparent red, green, blue colors' int 'Source type');*/ $gif = new GIFEncoder($frames, $delayTime, 0, 2, 0, 0, 0, "bin"); /* Possibles outputs: ================== Output as GIF for browsers : -> Header ( 'Content-type:image/gif' ); Output as GIF for browsers with filename: -> Header ( 'Content-disposition:Attachment;filename=myanimation.gif'); Output as file to store into a specified file: -> FWrite ( FOpen ( "myanimation.gif", "wb" ), $gif->GetAnimation ( ) );*/ Header('Content-type:image/gif'); echo $gif->GetAnimation(); }
/** * CONVERT VIDEOS TO FLV FORMAT * @param database A database connector object */ function draw($path_base, $path_new, $filename_noext, $filename_ext, $thumb_position, $full_position = "0:00:00") { defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR); defined('CONVERTPATH') ? null : define('CONVERTPATH', dirname(__FILE__)); $cmd_sinput = ''; $cmd_soutput = ''; $cmd_linput = ''; $cmd_loutput = ''; $cmd_dinput = ''; $cmd_doutput = ''; if(substr(PHP_OS, 0, 3) == "WIN") { defined('JPATH_SITE') ? null : define('JPATH_SITE', str_replace("\components\com_hwdvideoshare\converters", "", CONVERTPATH) ); } else { defined('JPATH_SITE') ? null : define('JPATH_SITE', str_replace("/components/com_hwdvideoshare/converters", "", CONVERTPATH) ); } // get joomla configuration include_once(JPATH_SITE.DS.'configuration.php'); // get hwdVideoShare general settings include_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'config.hwdvideoshare.php'); $c = hwd_vs_Config::get_instance(); // get hwdVideoShare server settings include_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'serverconfig.hwdvideoshare.php'); $s = hwd_vs_SConfig::get_instance(); // shared library $sharedlib = null; if ($c->sharedlibrarypath !== "") { $sharedlib = "export LD_LIBRARY_PATH=$c->sharedlibrarypath;"; } $path_sthumb = $path_base.DS.'thumbs'.DS.'temp_'.$filename_noext.'.jpg'; $path_lthumb = $path_base.DS.'thumbs'.DS.'temp_l_'.$filename_noext.'.jpg'; $path_dthumb = $path_base.DS.'thumbs'.DS.'temp_'.$filename_noext.'.gif'; $path_sthumb_orig = $path_base.DS.'thumbs'.DS.$filename_noext.'.jpg'; $path_lthumb_orig = $path_base.DS.'thumbs'.DS.'l_'.$filename_noext.'.jpg'; $path_dthumb_orig = $path_base.DS.'thumbs'.DS.$filename_noext.'.gif'; $path_seqthumb_orig = $path_base.DS.'thumbs'.DS.$filename_noext; $nthumbwidth = intval($c->con_thumb_n); $nwtype = gettype($nthumbwidth/2); if($nwtype !== "integer"){ $nthumbwidth = intval($nthumbwidth+1); } $nthumbheight = intval($c->con_thumb_n*$c->tar_fb); $nhtype = gettype($nthumbheight/2); if($nhtype !== "integer"){ $nthumbheight = intval($nthumbheight+1); } $lthumbwidth = intval($c->con_thumb_l); $lwtype = gettype($lthumbwidth/2); if($lwtype !== "integer"){ $lthumbwidth = intval($lthumbwidth+1); } $lthumbheight = intval($c->con_thumb_l*$c->var_fb); $lttype = gettype($lthumbheight/2); if($lttype !== "integer"){ $lthumbheight = intval($lthumbheight+1); } if(substr(PHP_OS, 0, 3) == "WIN") { $path_cmd_new = '"'.$path_new.'"'; $path_cmd_sthumb = '"'.$path_sthumb.'"'; $path_cmd_lthumb = '"'.$path_lthumb.'"'; $path_cmd_dthumb = '"'.$path_dthumb.'"'; $path_cmd_seqthumb = '"'.$path_seqthumb_orig.'"'; } else { $path_cmd_new = $path_new; $path_cmd_sthumb = $path_sthumb; $path_cmd_lthumb = $path_lthumb; $path_cmd_dthumb = $path_dthumb; $path_cmd_seqthumb = $path_seqthumb_orig; } //Static clearstatcache(); if ( @!file_exists($path_sthumb) || (@filesize($path_sthumb) == 0) ) { $cmd_sinput = "$s->ffmpegpath -y -i $path_cmd_new -ss $thumb_position -t 00:00:01 -s ".$nthumbwidth."x".$nthumbheight." -r 1 -f mjpeg $path_cmd_sthumb"; @exec("$sharedlib $cmd_sinput 2>&1", $cmd_soutput); } clearstatcache(); if ( @!file_exists($path_sthumb) || (@filesize($path_sthumb) == 0) ) { $cmd_sinput = "$s->ffmpegpath -y -i $path_cmd_new -ss $thumb_position -t 00:00:01 -s ".$nthumbwidth."x".$nthumbheight." -r 1 -f image2 $path_cmd_sthumb"; @exec("$sharedlib $cmd_sinput 2>&1", $cmd_soutput); } clearstatcache(); if ( !file_exists($path_sthumb) || (filesize($path_sthumb) == 0) ) { $cmd_sinput = "$s->ffmpegpath -ss $thumb_position -t 00:00:01 -i $path_cmd_new -an -r 1 -y -s ".$nthumbwidth."x".$nthumbheight." ".$path_cmd_sthumb.""; @exec("$sharedlib $cmd_sinput 2>&1", $cmd_soutput); } clearstatcache(); if ( !file_exists($path_sthumb) || (filesize($path_sthumb) == 0) ) { $thumb_position = "0:00:01"; $cmd_sinput = "$s->ffmpegpath -y -i $path_cmd_new -ss $thumb_position -t 00:00:01 -s ".$nthumbwidth."x".$nthumbheight." -r 1 -f mjpeg $path_cmd_sthumb"; @exec("$sharedlib $cmd_sinput 2>&1", $cmd_soutput); } clearstatcache(); if ( @!file_exists($path_sthumb) || (@filesize($path_sthumb) == 0) ) { $thumb_position = "0:00:01"; $cmd_sinput = "$s->ffmpegpath -y -i $path_cmd_new -ss $thumb_position -t 00:00:01 -s ".$nthumbwidth."x".$nthumbheight." -r 1 -f image2 $path_cmd_sthumb"; @exec("$sharedlib $cmd_sinput 2>&1", $cmd_soutput); } clearstatcache(); if ( @!file_exists($path_sthumb) || (@filesize($path_sthumb) == 0) ) { $thumb_position = "0:00:01"; $cmd_sinput = "$s->ffmpegpath -y -ss $thumb_position -t 00:00:01 -i $path_cmd_new -an -r 1 -y -s ".$nthumbwidth."x".$nthumbheight." ".$path_cmd_sthumb.""; @exec("$sharedlib $cmd_sinput 2>&1", $cmd_soutput); } //Large clearstatcache(); if ( @!file_exists($path_lthumb) || (@filesize($path_lthumb) == 0) ) { $cmd_linput = "$s->ffmpegpath -y -i $path_cmd_new -ss $thumb_position -t 00:00:01 -s ".$lthumbwidth."x".$lthumbheight." -r 1 -f mjpeg $path_cmd_lthumb"; @exec("$sharedlib $cmd_linput 2>&1", $cmd_soutput); } clearstatcache(); if ( @!file_exists($path_lthumb) || (@filesize($path_lthumb) == 0) ) { $cmd_linput = "$s->ffmpegpath -y -i $path_cmd_new -ss $thumb_position -t 00:00:01 -s ".$lthumbwidth."x".$lthumbheight." -r 1 -f image2 $path_cmd_lthumb"; @exec("$sharedlib $cmd_linput 2>&1", $cmd_soutput); } clearstatcache(); if ( !file_exists($path_lthumb) || (filesize($path_lthumb) == 0) ) { $cmd_linput = "$s->ffmpegpath -ss $thumb_position -t 00:00:01 -i $path_cmd_new -an -r 1 -y -s ".$lthumbwidth."x".$lthumbheight." ".$path_cmd_lthumb.""; @exec("$sharedlib $cmd_linput 2>&1", $cmd_soutput); } clearstatcache(); if ( !file_exists($path_lthumb) || (filesize($path_lthumb) == 0) ) { $thumb_position = "0:00:01"; $cmd_linput = "$s->ffmpegpath -y -i $path_cmd_new -ss $thumb_position -t 00:00:01 -s ".$lthumbwidth."x".$lthumbheight." -r 1 -f mjpeg $path_cmd_lthumb"; @exec("$sharedlib $cmd_linput 2>&1", $cmd_soutput); } clearstatcache(); if ( @!file_exists($path_lthumb) || (@filesize($path_lthumb) == 0) ) { $thumb_position = "0:00:01"; $cmd_linput = "$s->ffmpegpath -y -i $path_cmd_new -ss $thumb_position -t 00:00:01 -s ".$lthumbwidth."x".$lthumbheight." -r 1 -f image2 $path_cmd_lthumb"; @exec("$sharedlib $cmd_linput 2>&1", $cmd_soutput); } clearstatcache(); if ( @!file_exists($path_lthumb) || (@filesize($path_lthumb) == 0) ) { $thumb_position = "0:00:01"; $cmd_linput = "$s->ffmpegpath -y -ss $thumb_position -t 00:00:01 -i $path_cmd_new -an -r 1 -y -s ".$lthumbwidth."x".$lthumbheight." ".$path_cmd_lthumb.""; @exec("$sharedlib $cmd_linput 2>&1", $cmd_soutput); } //Dynamic if ( @!file_exists($path_dthumb) || (@filesize($path_dthumb) == 0) ) { if (function_exists('imagecreatefromjpeg')) { $cmd_dinput = "$s->ffmpegpath -i $path_cmd_new -an -r 0.2 -t 45 -y -s ".$nthumbwidth."x".$nthumbheight." ".$path_cmd_seqthumb."_%d.jpg"; @exec("$sharedlib $cmd_dinput 2>&1", $cmd_doutput); include_once JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'libraries'.DS.'GIFEncoder.class.php'; $frames = null; $time = null; for($i=1;$i<9;$i++){ if (file_exists($path_seqthumb_orig.'_'.$i.'.jpg')) { $imgname = $path_seqthumb_orig.'_'.$i.'.jpg'; $im = @imagecreatefromjpeg($imgname); /* Attempt to open */ imagegif($im, $path_seqthumb_orig.'_'.$i.'.gif'); $frames[] = $path_seqthumb_orig.'_'.$i.'.gif'; $time[] = 100; } } if (is_array($frames)) { $gif = new GIFEncoder ( $frames, // frames array $time, // elapsed time array 0, // loops (0 = infinite) 2, // disposal 0, 0, 0, // rgb of transparency "url" // source type ); $fh = fopen($path_dthumb, 'w') or die("can't open file"); fwrite($fh, $gif->GetAnimation()); fclose($fh); @imagedestroy($im); } for($i=1;$i<9;$i++){ @unlink($path_seqthumb_orig.'_'.$i.'.gif'); @unlink($path_seqthumb_orig.'_'.$i.'.jpg'); } } else { $cmd_dinput = "Could not use image manupulation functions. Check the GD image library has been installed"; $cmd_doutput = ""; } } $result = array(); $result[0] = 0; $result[1] = 0; $result[2] = $cmd_sinput; $result[3] = $cmd_soutput; $result[4] = $cmd_dinput; $result[5] = $cmd_doutput; $result[6] = 0; $result[7] = $cmd_linput; $result[8] = $cmd_loutput; if(file_exists($path_sthumb) && (filesize($path_sthumb) > 0)) { @unlink($path_sthumb_orig); if (!@rename($path_sthumb, $path_sthumb_orig)) { @copy($path_sthumb, $path_sthumb_orig); } if(file_exists($path_sthumb_orig) && (filesize($path_sthumb_orig) > 0)) { $result[0] = 1; @unlink($path_sthumb); } } if(file_exists($path_dthumb) && (filesize($path_dthumb) > 0)) { @unlink($path_dthumb_orig); if (!@rename($path_dthumb, $path_dthumb_orig)) { @copy($path_dthumb, $path_dthumb_orig); } if(file_exists($path_dthumb_orig) && (filesize($path_dthumb_orig) > 0)) { $result[1] = 1; @unlink($path_dthumb); } } if(file_exists($path_lthumb) && (filesize($path_lthumb) > 0)) { @unlink($path_lthumb_orig); if (!@rename($path_lthumb, $path_lthumb_orig)) { @copy($path_lthumb, $path_lthumb_orig); } if(file_exists($path_lthumb_orig) && (filesize($path_lthumb_orig) > 0)) { $result[6] = 1; @unlink($path_lthumb); } } $result = hwd_vs_GenerateThumbnail::generateOutput($result); return $result; }
imagegif($image); global $frames, $framed; $frames[] = ob_get_contents(); $framed[] = $_POST['speed']; ob_end_clean(); } $cnt = count($_FILES); for ($key = 1; $key <= $cnt; $key++) { $tmp_name = $_FILES["images" . $key]["tmp_name"]; $im = imagecreatefromstring(file_get_contents($tmp_name)); $resized = imagecreatetruecolor($_POST['width'], $_POST['height']); imagecopyresized($resized, $im, 0, 0, 0, 0, $_POST['width'], $_POST['height'], imagesx($im), imagesy($im)); frame($resized); } $gif = new GIFEncoder($frames, $framed, 0, 2, 0, 0, 0, 'bin'); echo $gif->GetAnimation(); } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name='robots' content='index,follow' /> <title>Create GIF image using php</title> <script src="jquery-latest.js"></script> <script src="jquery.MultiFile.js"></script> <script src="jquery.placeholder.js"></script> <style> input{ margin:10px; padding:10px; }
// Generate GIF from the $image // We want to put the binary GIF data into an array to be used later, // so we use the output buffer. ob_start(); imagegif($FirstBackgroundImage); $frames[] = ob_get_contents(); $framed[] = 80; // Delay in the animation. ob_end_clean(); // And again.. // Generate GIF from the $image // We want to put the binary GIF data into an array to be used later, // so we use the output buffer. ob_start(); $merged_image = "dps/{$uid}.gif"; imagegif($SecondBackgroundImage); $frames[] = ob_get_contents(); $framed[] = 80; // Delay in the animation. ob_end_clean(); // Generate the animated gif and save. $gif = new GIFEncoder($frames, $framed, 0, 2, 0, 0, 0, 'bin'); $fp = fopen($merged_image, 'w'); fwrite($fp, $gif->GetAnimation()); fclose($fp); $insert = mysql_query("insert into friendzone (`uid`, `name`, `path`,`email`,`fromName`,`fromPath`) values('" . $uid . "','" . $name . "','" . $merged_image . "','" . $email . "','" . $userName . "','" . $userDp . "')"); if ($insert) { echo $name . "|" . $merged_image; } else { echo "fail"; }
function GenerateGIFImages() { // We want to put the binary GIF data into an array to be used later, // so we use the output buffer. ob_start(); imagegif($this->{$FirstBackgroundImage}); $frames[] = ob_get_contents(); $framed[] = 80; // Delay in the animation. ob_end_clean(); ///////////////Generate GIF from the $image/////////////////////////////////////////////////////////////////// // We want to put the binary GIF data into an array to be used later, // so we use the output buffer. ob_start(); $merged_image = "dps/{$this}->{$uid}.gif"; imagegif($this->{$SecondBackgroundImage}); $frames[] = ob_get_contents(); $framed[] = 80; // Delay in the animation. ob_end_clean(); ///////////Generate the animated gif and save////////////////////////////////////////////////////////////// $gif = new GIFEncoder($frames, $framed, 0, 2, 0, 0, 0, 'bin'); $fp = fopen($merged_image, 'w'); fwrite($fp, $gif->GetAnimation()); fclose($fp); }
private function image_gif($savePath) { if ($this->ani_gif && is_array($this->ani_imageResized) && count($this->ani_imageResized) > 1) { $newa = array(); foreach ($this->ani_imageResized as $i) { ob_start(); imagegif($i); $gifdata = ob_get_clean(); $newa[] = $gifdata; } if ($gifmerge = new GIFEncoder($newa, $this->ani_delays, 9999, $this->ani_disposal, $this->ani_transparent['r'], $this->ani_transparent['g'], $this->ani_transparent['b'], "bin")) { FWrite(FOpen($savePath, "wb"), $gifmerge->GetAnimation()); } else { imagegif($this->ani_imageResized[0], $savePath); } } else { imagegif($this->imageResized, $savePath); } }
static function buildAnimateVerify($length = 4, $mode = 1, $width = 48, $height = 22, $verifyName = 'verify') { require 'String.class.php'; $randval = String::rand_string($length, $mode); $_SESSION[$verifyName] = md5($randval); $width = $length * 10 + 10 > $width ? $length * 10 + 10 : $width; for ($num = 0; $num < 10; $num++) { ob_start(); $im = @imagecreate($width, $height); $r = array(225, 255, 255, 223); $g = array(225, 236, 237, 255); $b = array(225, 236, 166, 125); $key = mt_rand(0, 3); $backColor = imagecolorallocate($im, $r[$key], $g[$key], $b[$key]); //背景色(随机) $borderColor = imagecolorallocate($im, 100, 100, 100); //边框色 $pointColor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); //点颜色 @imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor); @imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor); $stringColor = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120)); // 干扰 for ($i = 0; $i < 10; $i++) { $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44, $fontcolor); } for ($i = 0; $i < 25; $i++) { $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $pointColor); } for ($i = 0; $i < $length; $i++) { imagestring($im, 5, $i * 10 + 5, mt_rand(1, 8), $randval[$i], $stringColor); } imagegif($im); imagedestroy($im); $imagedata[] = ob_get_contents(); ob_clean(); } require 'GIFEncoder.class.php'; $gif = new \GIFEncoder($imagedata); ob_clean(); header('Content-type:image/gif'); echo $gif->GetAnimation(); }
/** * This function IS NOT PROVIDED IN FFMPEG-PHP as it creates the gif as frames are added. to save memory in * php and practicality purposes this isn't really possible. It will overwrite any file. * @access public * @uses GifEncoder * - @link http://www.phpclasses.org/browse/package/3163.html * - @link http://phpclasses.gifs.hu/show.php?src=GIFEncoder.class.php * - @author László Zsidi * - @license Freeware. * @param string $tmp_directory The temp directory to work with. (remember the trailing slash) * @return boolean */ public function saveNow($tmp_directory = '/tmp/') { if ($this->_saved === false) { $this->_saved = true; // check there are frames to make a gif if (!count($this->_frames)) { return false; } if (!class_exists('GIFEncoder')) { require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'gifencoder' . DIRECTORY_SEPARATOR . 'GIFEncoder.class.phpvideotoolkit.php'; } // save all the images from the ffmpeg_frames $files = array(); $delays = array(); $delay = 1 / $this->_frame_rate * 100; foreach ($this->_frames as $key => $frame) { $file = $tmp_directory . 'f*g-' . uniqid(time() . '-') . '.gif'; if (!imagegif($frame->toGDImage(), $file)) { return false; } // add file to array so it out deletes on close array_push($this->_unlink_files, $file); array_push($files, $file); array_push($delays, $delay); } // convert the images $gif = new GIFEncoder($files, $delays, $this->_loop_count, 2, 0, 0, 0, 0, 'url'); $gif_data = $gif->GetAnimation(); if (!$gif_data) { return false; } // write the gif if (!($handle = fopen($this->_output_file_path, 'w'))) { return false; } if (fwrite($handle, $gif_data) === false) { return false; } fclose($handle); return true; } return false; }
function getGifCode($paramArr) { $options = array('width' => 80, 'height' => 20, 'numCnt' => 4, 'text' => 'ABCD'); if (is_array($paramArr)) { $options = array_merge($options, $paramArr); } extract($options); $font = LJL_API_ROOT . '/Config/Fonts/Ga.ttf'; //$len = strlen($phrase); //$font_size=18; $len = $numCnt; $font_size = $width / ($len + 1) - 5; $size = $width / $len; $box = imagettfbbox($size, 0, $font, $text); $textWidth = $box[2] - $box[0]; $textHeight = $box[1] - $box[7]; $x = ($width - $textWidth) / 2; $y = ($height - $textHeight) / 2 + $size; $str = ''; for ($i = 0; $i < $len; $i++) { $str .= substr($text, $i, 1); } for ($num = 0; $num < 10; $num++) { ob_start(); $image = imagecreatetruecolor($width, $height); //创建图片 $bg_color = imagecolorallocate($image, 255, 255, 255); //设置背景颜色 $border_color = imagecolorallocate($image, 100, 100, 100); //设置边框颜色 $text_color = imagecolorallocate($image, 0, 0, 0); //设置验证码颜色 imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $bg_color); //填充图片背景色 imagerectangle($image, 0, 0, $width - 1, $height - 1, $border_color); //填充图片边框颜色 for ($i = 0; $i < 5; $i++) { $line_color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255)); //干扰线颜色 imageline($image, rand(0, $width), 0, $width, $height, $line_color); //画一条线段 } // 设定文字颜色数组 $colorList[] = ImageColorAllocate($image, 15, 73, 210); $colorList[] = ImageColorAllocate($image, 0, 64, 0); $colorList[] = ImageColorAllocate($image, 0, 0, 64); $colorList[] = ImageColorAllocate($image, 0, 128, 128); $colorList[] = ImageColorAllocate($image, 27, 52, 47); $colorList[] = ImageColorAllocate($image, 51, 0, 102); $colorList[] = ImageColorAllocate($image, 0, 0, 145); $colorList[] = ImageColorAllocate($image, 0, 0, 113); $colorList[] = ImageColorAllocate($image, 0, 51, 51); $colorList[] = ImageColorAllocate($image, 158, 180, 35); $colorList[] = ImageColorAllocate($image, 59, 59, 59); $colorList[] = ImageColorAllocate($image, 0, 0, 0); $colorList[] = ImageColorAllocate($image, 1, 128, 180); $colorList[] = ImageColorAllocate($image, 0, 153, 51); $colorList[] = ImageColorAllocate($image, 60, 131, 1); $colorList[] = ImageColorAllocate($image, 0, 0, 0); // 添加干扰线 for ($i = 0; $i < 500; $i++) { $dot_color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255)); //干扰点颜色 imagesetpixel($image, rand() % $width, rand() % $height, $dot_color); //画一个像素点 } for ($k = 0; $k < 3; $k++) { $colorRandom = mt_rand(0, sizeof($colorList) - 1); // $todrawline = rand(0,1); $todrawline = 1; if ($todrawline) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $colorList[$colorRandom]); } else { $w = mt_rand(0, $width); $h = mt_rand(0, $width); $num1 = rand(90, 180); $num2 = rand(180, 270); imagearc($image, $width - floor($w / 2), floor($h / 2), $w, $h, $num1, $num2, $colorList[$colorRandom]); } } for ($i = 0; $i < $len; $i++) { // imagettftext($image, $font_size, rand(-3, 3), $font_size / 2 + ($font_size + 5) * $i, $height / 1.25 - rand(2, 3), $text_color, $font, $str[$i]); //用规定字体向图像写入文本 imagettftext($image, $font_size, rand(-5, 5), $x + $font_size / 2 + ($font_size + 3) * $i, $y, $text_color, $font, $str[$i]); //用规定字体向图像写入文本 } imagegif($image); imagedestroy($image); $imagedata[] = ob_get_contents(); ob_clean(); } require_once 'GIFEncoder.class.php'; $gif = new GIFEncoder($imagedata); ob_clean(); //防止出现'图像因其本身有错无法显示'的问题 header('Content-type:image/gif'); echo $gif->GetAnimation(); }
$fill = imagecolorallocate($im, $fillArray[0], $fillArray[1], $fillArray[2]); imagettftext($im, $size / 1.3, 0, $x, $y, $fill, "FONT/times.ttf", $text); //$font = imageloadfont('./04b.gdf'); //imagestring($im, $font, $x, $y, $text, $fill); break; case "path": $points = parse_path($shape["points"]); //echo count($points).";"; $fillArray = sscanf($shape['fillColor'], '#%2x%2x%2x'); $fill = imagecolorallocate($im, $fillArray[0], $fillArray[1], $fillArray[2]); imagefilledpolygon($im, $points, count($points) / 2, $fill); imagesetthickness($im, $shape["lineWidth"]); $strokeArray = sscanf($shape['lineColor'], '#%2x%2x%2x'); $stroke = imagecolorallocate($im, $strokeArray[0], $strokeArray[1], $strokeArray[2]); imagepolygon($im, $points, count($points) / 2, $stroke); $points = array(); break; } } ob_start(); imagegif($im); imagedestroy($im); $data = ob_get_contents(); ob_end_clean(); array_push($gif_array, $data); array_push($framerate_array, 100 / $framerate); //echo "<img src='data:image/gif;base64,".base64_encode($data)."'><br><br>"; } $gif = new GIFEncoder($gif_array, $framerate_array, 0, 2, 0, 0, 0, "bin"); $animation = $gif->GetAnimation(); echo base64_encode($animation);
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(); }
function generate() { $this->no_cache(); $this->check(); $filename = array(); $frame_delays = array(); $image_string = $this->getImageString(); if ($this->use_background) { $this->background_selected = $this->randomArrayEl($this->background_array); } $ar_char_color = array(); for ($i = 0; $i < $this->string_length; $i++) { $ar_char_color[] = $this->getRGBCode($this->randomArrayEl($this->color['text'])); } $waveDirection = 0 == mt_rand(0, 1) ? 1 : -1; for ($frame_count = 1; $frame_count <= $this->frame_number; $frame_count++) { $random_font = $this->randomFont(); if ($random_font) { $x = (@imagefontwidth($random_font) + 4 + $this->text_space) * $this->string_length; if (!$this->use_background) { $height = (int) (@imagefontheight($random_font) * $this->font_size / 4) + $this->random_y_factor * 2; } } else { $x = (imagefontwidth($this->font_size) + $this->text_space) * $this->string_length; if (!$this->use_background) { $height = @imagefontheight($this->font_size) + 10 + $this->random_y_factor * 2; } } if (!$this->use_background) { $width = $x + 20; } if ($this->use_background) { if (preg_match('/\\.gif+$/', $this->background_selected)) { $this->image_type = 'gif'; $image = imagecreatefromgif($this->background_selected); } else { if (preg_match('/\\.(jpeg|jpg)+$/', $this->background_selected)) { $this->image_type = 'jpeg'; $image = imagecreatefromjpeg($this->background_selected); } else { if (preg_match('/\\.png+$/', $this->background_selected)) { $this->image_type = 'png'; $image = imagecreatefrompng($this->background_selected); } } } $a = getimagesize($this->background_selected); $width = $a[0]; $height = $a[1]; unset($a); if ($this->use_distortion) { $image = imagecreate($width, $height); $tempBgColor = imagecolorallocate($image, 255, 255, 255); imagefilledrectangle($image, 0, 0, $width, $height, $tempBgColor); } } else { $ar_background_color = array(); $ar_background_color[] = $this->getRGBCode($this->randomArrayEl($this->color['background'])); $image = imagecreate($width, $height); $background_color = imagecolorallocate($image, $ar_background_color[0][0], $ar_background_color[0][1], $ar_background_color[0][2]); $border_color = imagecolorallocate($image, 0, 0, 0); imagerectangle($image, 0, 0, $width - 1, $height - 1, $border_color); imagefilledrectangle($image, 1, 1, $width - 1, $height - 1, $background_color); } if ($this->use_grid) { $ar_grid_color = array(); $ar_grid_color[] = $this->getRGBCode($this->randomArrayEl($this->color['grid'])); $grid_color = imagecolorallocate($image, $ar_grid_color[0][0], $ar_grid_color[0][1], $ar_grid_color[0][2]); for ($i = 0; $i < $this->grid_density; $i++) { if ($this->randomize_grid) { $i_factor = (mt_rand(1, 100) + microtime()) % mt_rand(2, 100); $i_factor++; $i_factor2 = (mt_rand(1, 100) + microtime()) % mt_rand(2, 100); $i_factor2++; } else { $i_factor = 3; $i_factor2 = 3; } imagesetthickness($image, mt_rand(0, 2)); imageline($image, $i * ($width / $i_factor), 2, $i * ($width / $i_factor2), $height, $grid_color); } if ($this->randomize_grid) { $i_factor = (mt_rand(1, 100) + microtime()) % mt_rand(2, 100); $i_factor++; $i_factor2 = (mt_rand(1, 100) + microtime()) % mt_rand(2, 100); $i_factor2++; } else { $i_factor = 5; $i_factor2 = 5; } imageline($image, 0, $i * ($height / $i_factor), $width, $i * ($height / $i_factor2), $grid_color); if ($this->randomize_grid) { imageline($image, 0, $i * ($height / 3), $width, $i * ($height / 3), $grid_color); } } $x = sprintf("%d", ($width - $x) / 2); if ($random_font) { $y = ($height - imagefontheight($random_font)) / 2; } else { $y = ($height - imagefontheight($this->font_size)) / 2; } $offset_x = 0; $x += mt_rand(0, 2); for ($i = 0; $i < $this->string_length; $i++) { $char = substr($image_string, $i, 1); $x2 = $x + $offset_x - 1 + mt_rand(0, 1); $y2 = $y - $this->random_y_factor + mt_rand(0, $this->random_y_factor * 2); $y2 = $y + 10; $foreground_color = imagecolorallocate($image, $ar_char_color[$i][0], $ar_char_color[$i][1], $ar_char_color[$i][2]); if ($random_font) { $angle = $this->randomAngle(); if ($this->overlap_text) { if ($this->use_background) { imagettftext($image, $this->font_size, $angle + mt_rand(0, 1), $x2 + $this->randomOverlapFactor(), $y2 + $this->randomOverlapFactor(), $foreground_color, $this->randomFont(), $char); } else { if (mt_rand(0, 10) <= 9) { $comp = $this->getColorComplement($ar_char_color[$i], mt_rand(1, 13), mt_rand(1, 13), mt_rand(1, 13)); $comp_color = imagecolorallocate($image, $comp[0], $comp[1], $comp[2]); } else { $comp_color = $foreground_color; } imagettftext($image, $this->font_size, $angle + mt_rand(0, 1), $x2 + $this->randomOverlapFactor(), $y2 + $this->randomOverlapFactor(), $comp_color, $this->randomFont(), $char); } } imagettftext($image, $this->font_size, $angle, $x2, $y2, $foreground_color, $this->randomFont(), $char); $offset_x += imagefontwidth($random_font) * $this->font_size / 8 + $this->text_space; } else { imagestring($image, $this->font_size, $x2, $y2, $char, $foreground_color); $offset_x += imagefontwidth($this->font_size) + $this->text_space; } } if ($this->use_grid) { $ar_grid_color = array(); $ar_grid_color[] = $this->getRGBCode($this->randomArrayEl($this->color['grid'])); $grid_color = imagecolorallocate($image, $ar_grid_color[0][0], $ar_grid_color[0][1], $ar_grid_color[0][2]); for ($i = 0; $i < 2; $i++) { if ($this->randomize_grid) { $i_factor = (mt_rand(1, 100) + microtime()) % mt_rand(2, 100); $i_factor++; $i_factor2 = (mt_rand(1, 100) + microtime()) % mt_rand(2, 100); $i_factor2++; } else { $i_factor = 3; $i_factor2 = 3; } imagesetthickness($image, mt_rand(1, 2)); imageline($image, $i * ($width / $i_factor), 2, $i * ($width / $i_factor2), $height, $grid_color); } for ($i = 0; $i < 1; $i++) { if ($this->randomize_grid) { $i_factor = (mt_rand(1, 100) + microtime()) % mt_rand(2, 100); $i_factor++; $i_factor2 = (mt_rand(1, 100) + microtime()) % mt_rand(2, 100); $i_factor2++; } else { $i_factor = 5; $i_factor2 = 5; } imageline($image, 0, $i * ($height / $i_factor), $width, $i * ($height / $i_factor2), $grid_color); } } if ($this->use_distortion) { if ('normal' == $this->distortion_type) { $image = $this->distortImage($image); } else { if ('slice' == $this->distortion_type) { $image = $this->distortImageSlice($image); } else { if ('wave' == $this->distortion_type) { $image = $this->distortImageWave($image, $waveDirection); } } } } if ($this->frame_number > 1) { $rand_filename = $this->temp_dir . md5(microtime() . getenv('REMOTE_ADDR')) . mt_rand(1, 999) . '.txt'; $fp = fopen($rand_filename, 'w+'); if ($fp) { flock($fp, 2); fwrite($fp, ''); flock($fp, 3); fclose($fp); imagegif($image, $rand_filename); imagedestroy($image); $filename[] = $rand_filename; $frame_delays[] = $this->frame_delay; unset($image, $rand_filename); } } } if (!headers_sent()) { session_start(); header('Content-type: image/gif'); $_SESSION[$this->session_name] = $this->string_crypt($image_string); } else { @trigger_error('generate() was called after headers already sent.', E_USER_ERROR); } if (1 == $this->frame_number) { if ('gif' == $this->image_type) { imagegif($image); } else { if ('jpeg' == $this->image_type) { imagejpeg($image); } else { if ('png' == $this->image_type) { imagepng($image); } } } imagedestroy($image); } else { if (count($filename) > 0) { $angif = new GIFEncoder($filename, $frame_delays, 0, 2, 0, 0, 0, 'url'); echo $angif->GetAnimation(); foreach ($filename as $s) { @unlink($s); } unset($angif, $filename, $frame_delays, $s); } } }
/** * 输出图片. * * @access public * @return boolean 成功返回 TRUE, 否则返回 FALSE. */ public function output() { $gifEncoder = new GIFEncoder($this->_frames, $this->_delays, 0, 2, 0, 0, 0, 'bin'); $mime = image_type_to_mime_type(IMAGETYPE_GIF); header('Content-type: ' . $mime); return imagegif($gifEncoder->GetAnimation()); }
/** * ImageCode 生成GIF图片验证 * @param $string 字符串 * @param $width 宽度 * @param $height 高度 * */ function checkcode($string = '', $width = 75, $height = 25) { $authstr = $string ? $string : (time() % 2 == 0 ? mt_rand(1000, 9999) : mt_rand(10000, 99999)); $board_width = $width; $board_height = $height; // 生成一个32帧的GIF动画 for ($i = 0; $i < 32; $i++) { ob_start(); $image = imagecreate($board_width, $board_height); imagecolorallocate($image, 0, 0, 0); // 设定文字颜色数组 $colorList[] = ImageColorAllocate($image, 15, 73, 210); $colorList[] = ImageColorAllocate($image, 0, 64, 0); $colorList[] = ImageColorAllocate($image, 0, 0, 64); $colorList[] = ImageColorAllocate($image, 0, 128, 128); $colorList[] = ImageColorAllocate($image, 27, 52, 47); $colorList[] = ImageColorAllocate($image, 51, 0, 102); $colorList[] = ImageColorAllocate($image, 0, 0, 145); $colorList[] = ImageColorAllocate($image, 0, 0, 113); $colorList[] = ImageColorAllocate($image, 0, 51, 51); $colorList[] = ImageColorAllocate($image, 158, 180, 35); $colorList[] = ImageColorAllocate($image, 59, 59, 59); $colorList[] = ImageColorAllocate($image, 0, 0, 0); $colorList[] = ImageColorAllocate($image, 1, 128, 180); $colorList[] = ImageColorAllocate($image, 0, 153, 51); $colorList[] = ImageColorAllocate($image, 60, 131, 1); $colorList[] = ImageColorAllocate($image, 0, 0, 0); $fontcolor = ImageColorAllocate($image, 0, 0, 0); $gray = ImageColorAllocate($image, 245, 245, 245); $color = imagecolorallocate($image, 255, 255, 255); $color2 = imagecolorallocate($image, 255, 0, 0); imagefill($image, 0, 0, $gray); $space = 15; // 字符间距 if ($i > 0) { for ($k = 0; $k < strlen($authstr); $k++) { $colorRandom = mt_rand(0, sizeof($colorList) - 1); $float_top = rand(0, 4); $float_left = rand(0, 3); imagestring($image, 6, $space * $k, $top + $float_top, substr($authstr, $k, 1), $colorList[$colorRandom]); } } for ($k = 0; $k < 20; $k++) { $colorRandom = mt_rand(0, sizeof($colorList) - 1); imagesetpixel($image, rand() % 70, rand() % 15, $colorList[$colorRandom]); } // 添加干扰线 for ($k = 0; $k < 3; $k++) { $colorRandom = mt_rand(0, sizeof($colorList) - 1); // $todrawline = rand(0,1); $todrawline = 1; if ($todrawline) { imageline($image, mt_rand(0, $board_width), mt_rand(0, $board_height), mt_rand(0, $board_width), mt_rand(0, $board_height), $colorList[$colorRandom]); } else { $w = mt_rand(0, $board_width); $h = mt_rand(0, $board_width); imagearc($image, $board_width - floor($w / 2), floor($h / 2), $w, $h, rand(90, 180), rand(180, 270), $colorList[$colorRandom]); } } imagegif($image); imagedestroy($image); $imagedata[] = ob_get_contents(); ob_clean(); ++$i; } $gif = new GIFEncoder($imagedata); Header('Content-type:image/gif'); // echo $gif->GetAnimation(); echo $gif->GetAnimation(); }
/** * Create an animated gif of the image rotating around Z axis * @author nchourrout * @version 0.1 * @param time_div integer Duration in ms between two frames (default : 50ms) */ public function createAnimatedGIF($time_div = 50) { $this->ext = "gif"; for ($i = 1; $i < 6; $i++) { $angle = 0.1 + M_PI / 12 * $i; $this->rotate(0, 0, $angle); $this->save($i . ".gif"); $frames[] = $this->output_directory . $i . ".gif"; $time[] = $time_div; } $loops = 0; //infinite $gif = new GIFEncoder($frames, $time, $loops, 2, 0, 0, 0, "url"); Header('Content-type:image/gif'); echo $gif->GetAnimation(); //Modifier cette ligne par quelquechose qui permette juste de stocker l'image dans un fichier for ($i = 1; $i < 6; $i++) { @unlink($this->output_directory . $i . ".gif"); } }
public function generateGif() { include 'libs/GIFEncoder.class.php'; $gif = new GIFEncoder($this->animation['frames'], $this->animation['frame_delays'], 0, 2, 0, 0, 0, 'bin'); $animationName = uniqid('pixelCannon') . '.gif'; $fp = fopen('_generated/animations/' . $animationName, 'w'); fwrite($fp, $gif->GetAnimation()); fclose($fp); return '_generated/animations/' . $animationName; echo '<img width="800" height="400" src="http://mm0030165.mediamonks.local/projects/yoda/_generated/animations/' . $animationName . '">'; die; }
/** * 生成GIF动画格式验证码 * @param string $cookiePre cookie前缀 * @param int $num 验证码显示位数 * @param int $cookieMinute cookie存活时间(单位:分) * @param int $h 验证高度 * @param int $onlyDigit 是否只包含数字,否则将包含字母 */ public static function gifAuthcode($cookiePre = '', $num = 5, $cookieMinute = 3, $h = 20, $onlyDigit = false) { $params = self::getParams($cookiePre, $num, $cookieMinute, $h, $onlyDigit); $imagedata = array(); // 生成一个32帧的GIF动画 for ($i = 0; $i < 12; $i++) { ob_start(); $image = imagecreate($params['width'], $params['height']); imagecolorallocate($image, 0, 0, 0); // 设定文字颜色数组 $colorList[] = ImageColorAllocate($image, 15, 73, 210); $colorList[] = ImageColorAllocate($image, 0, 64, 0); $colorList[] = ImageColorAllocate($image, 0, 0, 64); $colorList[] = ImageColorAllocate($image, 0, 128, 128); $colorList[] = ImageColorAllocate($image, 27, 52, 47); $colorList[] = ImageColorAllocate($image, 51, 0, 102); $colorList[] = ImageColorAllocate($image, 0, 0, 145); $colorList[] = ImageColorAllocate($image, 0, 0, 113); $colorList[] = ImageColorAllocate($image, 0, 51, 51); $colorList[] = ImageColorAllocate($image, 158, 180, 35); $colorList[] = ImageColorAllocate($image, 59, 59, 59); $colorList[] = ImageColorAllocate($image, 0, 0, 0); $colorList[] = ImageColorAllocate($image, 1, 128, 180); $colorList[] = ImageColorAllocate($image, 0, 153, 51); $colorList[] = ImageColorAllocate($image, 60, 131, 1); $colorList[] = ImageColorAllocate($image, 0, 0, 0); $fontcolor = ImageColorAllocate($image, 0, 0, 0); $gray = ImageColorAllocate($image, 245, 245, 245); $color = imagecolorallocate($image, 255, 255, 255); $color2 = imagecolorallocate($image, 255, 0, 0); imagefill($image, 0, 0, $gray); $space = 12; // 字符间距 if ($i > 0) { $len = strlen($params['string']); for ($k = 0; $k < $len; $k++) { $colorRandom = mt_rand(0, sizeof($colorList) - 1); $float_top = rand(0, 4); $float_left = rand(0, 3); imagestring($image, 5, $space * $k + $float_left, $float_top, $params['string'][$k], $colorList[$colorRandom]); } } for ($k = 0; $k < 20; $k++) { $colorRandom = mt_rand(0, sizeof($colorList) - 1); imagesetpixel($image, rand() % 70, rand() % 15, $colorList[$colorRandom]); } // 添加干扰线 for ($k = 0; $k < 3; $k++) { $colorRandom = mt_rand(0, sizeof($colorList) - 1); // $todrawline = rand(0,1); $todrawline = 1; if ($todrawline) { imageline($image, mt_rand(0, $params['width']), mt_rand(0, $params['height']), mt_rand(0, $params['width']), mt_rand(0, $params['height']), $colorList[$colorRandom]); } else { $w = mt_rand(0, $params['width']); $h = mt_rand(0, $params['width']); imagearc($image, $params['width'] - floor($w / 2), floor($h / 2), $w, $h, rand(90, 180), rand(180, 270), $colorList[$colorRandom]); } } imagegif($image); imagedestroy($image); $imagedata[] = ob_get_contents(); ob_clean(); ++$i; } $gif = new GIFEncoder($imagedata, 5, 0, 2, 0, 0, 0, 'bin'); Header('Content-type:image/gif'); echo $gif->GetAnimation(); }
/** * 保存当前GIF图片 * @param string $gifname 图片名称 */ public function save($gifname) { $gif = new GIFEncoder($this->frames, $this->delays, 0, 2, 0, 0, 0, 'bin'); file_put_contents($gifname, $gif->GetAnimation()); }
/** * write the frames to a file depending on the output format */ protected function _writeFramesToTargetFile() { $delays = array(); for ($i = 0; $i < count($this->_frames); $i++) { $delays[] = $this->_options['millisecondsBetweenFrames']; } $gif = new GIFEncoder($this->_frames, $delays, 0, 2, 0, 0, 0, 0, "bin"); file_put_contents($this->_tempFilePath, $gif->GetAnimation()); }