diff --git a/inc/config.php b/inc/config.php index 9398596c..1474bd46 100644 --- a/inc/config.php +++ b/inc/config.php @@ -102,7 +102,7 @@ // Use a persistent connection (experimental) $config['db']['persistent'] = false; // Anything more to add to the DSN string (eg. port=xxx;foo=bar) - $config['db']['dsn'] = ''; + $config['db']['dsn'] = 'charset=UTF-8'; // Timeout duration in seconds (not all drivers support this) $config['db']['timeout'] = 5; @@ -363,6 +363,9 @@ // Use Imagick instead of GD (some further config options below are ignored if set) $config['imagick'] = false; + // Use the command line version of ImagickMagick rather than the PHP bindings. + $config['imagick_convert'] = false; + // Regular expression to check for IE MIME type detection XSS exploit. To disable, comment the line out // https://github.com/savetheinternet/Tinyboard/issues/20 $config['ie_mime_type_detection'] = '/<(?:body|head|html|img|plaintext|pre|script|table|title|a href|channel|scriptlet)/i'; diff --git a/inc/image.php b/inc/image.php index 85200104..45a7df18 100644 --- a/inc/image.php +++ b/inc/image.php @@ -14,7 +14,7 @@ $this->format = $format; if($config['imagick']) { - $classname = 'ImageImagick'; + $classname = $config['imagick_convert'] ? 'ImageConvert' : 'ImageImagick'; } else { $classname = 'Image' . strtoupper($this->format); if(!class_exists($classname)) { @@ -39,7 +39,7 @@ global $config; if($config['imagick']) { - $classname = 'ImageImagick'; + $classname = $config['imagick_convert'] ? 'ImageConvert' : 'ImageImagick'; } else { $classname = 'Image' . strtoupper($extension); if(!class_exists($classname)) { @@ -200,13 +200,53 @@ } } else { $this->image = clone $this->original; - // only resize one frame $this->image->scaleImage($this->width, $this->height, false); } } } + class ImageConvert extends ImageBase { + public $width, $height, $temp; + + public function init() { + global $config; + + $this->temp = tempnam($config['tmp'], 'imagick'); + + } + public function from() { + if(!$size = @getimagesize($this->src)) + return $this->image = false; + + $this->width = $size[0]; + $this->height = $size[1]; + + // mark as valid + $this->image = true; + } + public function to($src) { + rename($this->temp, $src); + } + public function width() { + return $this->width; + } + public function height() { + return $this->height; + } + public function destroy() { + unlink($this->temp); + } + public function resize() { + global $config; + + $quality = $config['thumb_quality'] * 10; + + if(shell_exec("convert -flatten -filter Point -resize {$this->width}x{$this->height} -quality {$quality} " . escapeshellarg($this->src) . " " . escapeshellarg($this->temp))) + error('Failed to resize image!'); + } + } + class ImagePNG extends ImageBase { public function from() { $this->image = @imagecreatefrompng($this->src);