/** * Saves the animated gif. * * @access public * @author Oliver Lillie * @param string $save_path The path to save the animated gif to. * @return PHPVideoToolkit\Image Returns a new instance of PHPVideoToolkit\Image with the new animated gif as the src. * @throws PHPVideoToolkit\AnimatedGifException If the convert process encounters an error. */ public function save($save_path) { $save_path = parent::save($save_path); // build the gifsicle process $process = new ProcessBuilder('convert', $this->_config); // set the frame duration $process->add('-delay')->add($this->_frame_delay * 100); $process->add('-loop')->add($this->_loop_count === AnimatedGif::UNLIMITED_LOOPS ? '0' : $this->_loop_count + 1); // add in all the frames foreach ($this->_frames as $path) { $process->add($path); } if ($this->_config->gif_transcoder_convert_use_dither === true) { $process->add('-ordered-dither')->add($this->_config->gif_transcoder_convert_dither_order); } if ($this->_config->gif_transcoder_convert_use_coalesce === true) { $process->add('-coalesce'); } $process->add('-layers')->add('OptimizeTransparency'); if ($this->_config->gif_transcoder_convert_use_map === true) { $process->add('+map'); } // add the output path $process->add($save_path); // execute the process. $exec = $process->getExecBuffer(); $exec->setBlocking(true)->execute(); // check for any gifsicle errors if ($exec->hasError() === true) { throw new AnimatedGifException('AnimatedGif save using `convert` "' . $save_path . '" failed. Any additional convert message follows: ' . $exec->getBuffer()); } return new Image($save_path, $this->_config); }
/** * Saves the animated gif. * * @access public * @author Oliver Lillie * @param string $save_path * @param float $frame_delay The delay of each frame. * @return Image */ public function save($save_path, $frame_delay = 0.1) { parent::save($save_path, $frame_delay); // build the gifsicle process $process = new ProcessBuilder('convert', $this->_config); // set the frame duration $process->add('-delay')->add($frame_delay * 100); $process->add('-loop')->add($this->_loop_count === AnimatedGif::UNLIMITED_LOOPS ? '0' : $this->_loop_count + 1); // add in all the frames foreach ($this->_frames as $path) { $process->add($path); } // add the output path $process->add($save_path); // execute the process. $exec = $process->getExecBuffer(); $exec->setBlocking(true)->execute(); // check for any gifsicle errors if ($exec->hasError() === true) { throw new FfmpegProcessPostProcessException('AnimatedGif save using `convert` "' . $save_path . '" failed. Any additional convert message follows: ' . $exec->getBuffer()); } return new Image($save_path, $this->_config); }
/** * Saves the animated gif. * * @access public * @author Oliver Lillie * @param string $save_path * @param float $frame_delay The delay of each frame. * @return Image */ public function save($save_path, $frame_delay = 0.1) { parent::save($save_path, $frame_delay); // build the gifsicle process $gifsicle_process = new ProcessBuilder('gifsicle', $this->_config); // add in all the frames foreach ($this->_frames as $path) { $gifsicle_process->add($path); } // set the looping count if ($this->_loop_count === AnimatedGif::UNLIMITED_LOOPS) { $gifsicle_process->add('-l'); } else { $gifsicle_process->add('-l')->add($this->_loop_count); } // set the frame duration //$gifsicle_process->add('-d')->add($frame_delay*1000); // add the output path $gifsicle_process->add('-o')->add($save_path); // execute the process. $exec = $gifsicle_process->getExecBuffer(); $exec->setBlocking(true)->execute(); $this->__destruct(); // check for any gifsicle errors if ($exec->hasError() === true) { throw new FfmpegProcessPostProcessException('AnimatedGif save using `gifsicle` save "' . $save_path . '" failed. Any additional gifsicle message follows: ' . $exec->getBuffer()); } return new Image($save_path, $this->_config); }