HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux WebLive 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/wpprm_old/wp-content/themes/ronneby/inc/lib/gifanim/class.php
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
/**
 * Resize gif animated images
 */
class SBResizeGifImage {
	private $_images;
	private $_info;

	/**
	 * Load Image
	 * @param string $src Source path
	 */
	public function __construct($src) {
		$this->_check_required_libraries();
		
		$this->_images = new Imagick($src);

		$this->_update_info();
		$this->_validate_image_type();
	}

	/**
	 * Resize Image
	 * 
	 * @param int $max_w	Width in pixels
	 * @param int  $max_h	height in pixels
	 * @param boolean $crop	Crop or resize
	 */
	public function resize($max_w, $max_h, $crop=true) {

		list($width, $height) = $this->getSize();

		if ( ( $width == $max_w ) && ( $height == $max_h ) ) {
			return;
		}

		$this->_images = $this->_images->coalesceImages();

		do {
			if ($crop) {
				$this->_images->cropThumbnailImage($max_w, $max_h);
			} else {
				$this->_images->resizeImage($max_w, $max_h, Imagick::FILTER_LANCZOS, 1, true);
			}
		} while ($this->_images->nextImage());
		
		$this->_images->optimizeImageLayers();
		 
		// Releaze memory
		$this->_images = $this->_images->deconstructImages();
		$this->_update_info();
	}

	/**
	 * Save image
	 * @param string $out	Result Image Path
	 */
	public function save($out) {
		// Save image
		$this->_images->writeImages($out, true);
	}

	/**
	 * Get image size
	 * @return array	[width, height]
	 */
	public function getSize() {
		return array(
			$this->_info['geometry']['width'],
			$this->_info['geometry']['height'],
		);
	}

	private function _update_info() {
		$this->_info = $this->_images->identifyImage();
	}

	private function _check_required_libraries() {
		if (!class_exists('Imagick')) {
			throw new Exception("Imagick was not intalled :o(");
		}
	}

	private function _validate_image_type() {
		$format = strtolower($this->_info['format']);

		if (!strcmp(substr($format, 0, 3), 'gif')===0) {
			throw new Exception("Unsapported format: '{$format}'");
		}
	}
}