public function postProcessCreateAnimatedGif(array $output) { // create the gif $gif = AnimatedGif::createFrom($output, 1 / $this->_format['video_frame_rate'], $this->_format['gif_loop_count'], $this->_config); // break out the dirname incase of relative pathways. $name = basename($this->_original_save_path); $path = realpath(dirname($this->_original_save_path)); $save_path = $path . DIRECTORY_SEPARATOR . $name; // save the gif $image = $gif->save($save_path); // remove tmp frame files foreach ($output as $output_image) { @unlink($output_image->getMediaPath()); } // return an updated output return $image; }
$text = $interval->format('00:00:00:00'); imagettftext($image, $font['size'], $font['angle'], $font['x-offset'], $font['y-offset'], $font['color'], $font['file'], $text); ob_start(); imagegif($image); $frames[] = ob_get_contents(); $delays[] = $delay; $loops = 1; ob_end_clean(); break; } else { // Open the first source image and add the text. $image = imagecreatefrompng('images/countdown.png'); $text = $interval->format('0%a %H %I %S'); imagettftext($image, $font['size'], $font['angle'], $font['x-offset'], $font['y-offset'], $font['color'], $font['file'], $text); ob_start(); imagegif($image); $frames[] = ob_get_contents(); $delays[] = $delay; $loops = 0; ob_end_clean(); } $now->modify('+1 second'); } //expire this image instantly header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache'); $gif = new AnimatedGif($frames, $delays, $loops); $gif->display();
public function postProcessCreateAnimatedGif(array $output, Media $media, $save_path, $overwrite, $video_frame_rate, $gif_loop_count, $gif_frame_delay) { // create the gif $gif = AnimatedGif::createFrom($output, 1 / $video_frame_rate, $gif_loop_count, $this->_config); // break out the dirname incase of relative pathways. $name = basename($save_path); $path = realpath(dirname($save_path)); $save_path = $path . DIRECTORY_SEPARATOR . $name; // save the gif $image = $gif->setFrameDelay($gif_frame_delay)->setOverwriteMode($overwrite)->save($save_path, $overwrite); // remove tmp frame files foreach ($output as $output_image) { @unlink($output_image->getMediaPath()); } // return an updated output return $image; }
$minutes = '0' . $minutes; } if (preg_match('/^[0-9]\\:/', $seconds)) { $seconds = '0' . $seconds; } imagettftextSp($image, $font['size'], $font['angle'], 32, 48, $font['color'], $font['file'], $hours, 16); imagettftextSp($image, $font['size'], $font['angle'], 132, 48, $font['color'], $font['file'], $minutes, 16); imagettftextSp($image, $font['size'], $font['angle'], 232, 48, $font['color'], $font['file'], $seconds, 16); ob_start(); imagesavealpha($image, true); imagecolortransparent($image, 127 << 24); imagegif($image); $frames[] = ob_get_contents(); $delays[] = $delay; $loops = 0; ob_end_clean(); $now->modify('+1 ' . $t); } // Create GIF animation $gif = new AnimatedGif($frames, $delays, $loops); // if($is_cache){ file_put_contents($cache_file, $gif->getAnimation()); // } header('Expires: ' . gmdate('D, d M Y H:i:s T', strtotime($time))); //expire this image header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache'); // Render image $gif->display();
exit; } // reverse frames if ($_POST['rev'] == 'true') { $backframes = array_reverse($frames); $newframes = array_merge($frames, $backframes); } else { $newframes = $frames; } $loops = $_POST['loops'] > 0 ? $_POST['loops'] : 0; // set framelength $framelength = $_POST['speed'] > 0 ? $_POST['speed'] : 5; $delays = array_fill(0, count($newframes), $framelength); if ($_POST['rev'] == 'true' && $_POST['pause'] > 0) { $delays[0] = $_POST['pause']; $delays[count($frames)] = $_POST['pause']; } $gif = new AnimatedGif($newframes, $delays, $loops); $newFileName = str_replace(array('.jpg', '.gif'), '', safeFileName($_POST['newFileName'])) . '.gif'; if (!($newgif = fopen(IMAGEBASEDIR . $newFileName, "wb"))) { $return['errorText'] .= "<li>Cannot open {$newFileName}.</li>"; } else { if (!fwrite($newgif, $gif->GetAnimation())) { $return['errorText'] .= "<li>Cannot write to {$newFileName}.</li>"; } else { $return['error'] = false; } } $return['gif'] = $newFileName; $return['errorText'] .= "</ul>"; scriptReturn($return);