Browse Source

convert: Don't rely on PHP GD to get the image dimensions; use `identify`.

pull/40/head
Michael Save 12 years ago
parent
commit
c6478b378f
  1. 22
      inc/image.php

22
inc/image.php

@ -219,15 +219,17 @@
$this->temp = tempnam($config['tmp'], 'imagick'); $this->temp = tempnam($config['tmp'], 'imagick');
} }
public function from() { public function from() {
if(!$size = @getimagesize($this->src)) $size = trim(shell_exec('identify -format "%w %h" ' . escapeshellarg($this->src . '[0]')));
return $this->image = false; if(preg_match('/^(\d+) (\d+)$/', $size, $m)) {
$this->width = $m[1];
$this->width = $size[0]; $this->height = $m[2];
$this->height = $size[1];
$this->image = true;
// mark as valid } else {
$this->image = true; // mark as invalid
$this->image = false;
}
} }
public function to($src) { public function to($src) {
rename($this->temp, $src); rename($this->temp, $src);
@ -247,7 +249,7 @@
$quality = $config['thumb_quality'] * 10; $quality = $config['thumb_quality'] * 10;
if(shell_exec("convert -flatten -antialias -filter Point -scale {$this->width}x{$this->height} -quality {$quality} " . escapeshellarg($this->src . '[0]') . " " . escapeshellarg($this->temp))) if(shell_exec("convert -flatten -antialias -filter Point -scale {$this->width}x{$this->height} -quality {$quality} " . escapeshellarg($this->src . '[0]') . " " . escapeshellarg($this->temp)) || !file_exists($this->temp))
error('Failed to resize image!'); error('Failed to resize image!');
} }
} }

Loading…
Cancel
Save