Imagemagick:无法从gif动画中制作静态缩略图


Imagemagick: can not make a static thumbnail from gif animation

我使用jQuery File Upload脚本。该包还包含一个php脚本,用于处理文件和制作缩略图。一切都很好,但我需要创建静态缩略图,以防用户上传动画gif文件。

下面是创建缩略图的功能。

我已经为"处理动画GIF"评论了所有内容:因为我不想要动画GIF中的动画缩略图。

并添加了一行:

mail('my@email', 'file_path', "$file_path");

上传时,我收到的电子邮件文件路径如下:/var/www/images/image.gif

然后我添加了以下行,从第一帧中制作缩略图

$file_path = $file_path[0];
mail('my@email', 'file_path', "$file_path");

现在我收到空的电子邮件,缩略图没有创建。因此,变量$file_path[0]不存在。为什么?

如何从动画gif创建静态缩略图?

protected function imagemagick_create_scaled_image($file_name, $version, $options) {
list($file_path, $new_file_path) =
$this->get_scaled_image_file_paths($file_name, $version);
$file_path = $file_path[0];
mail('my@email', 'file_path', "$file_path");
$resize = @$options['max_width']
.(empty($options['max_height']) ? '' : 'x'.$options['max_height']);
if (!$resize && empty($options['auto_orient'])) {
if ($file_path !== $new_file_path) {
return copy($file_path, $new_file_path);
}
return true;
}
$cmd = $this->options['convert_bin'];
if (!empty($this->options['convert_params'])) {
$cmd .= ' '.$this->options['convert_params'];
}
$cmd .= ' '.escapeshellarg($file_path);
if (!empty($options['auto_orient'])) {
$cmd .= ' -auto-orient';
}

//if ($resize) {
// Handle animated GIFs:
//$cmd .= ' -coalesce';
//if (empty($options['crop'])) {
//$cmd .= ' -resize '.escapeshellarg($resize.'>');
//} else {
//$cmd .= ' -resize '.escapeshellarg($resize.'^');
//$cmd .= ' -gravity center';
//$cmd .= ' -crop '.escapeshellarg($resize.'+0+0');
//}
// Make sure the page dimensions are correct (fixes offsets of animated GIFs):
//$cmd .= ' +repage';
//}

if (!empty($options['convert_params'])) {
$cmd .= ' '.$options['convert_params'];
}
$cmd .= ' '.escapeshellarg($new_file_path);
exec($cmd, $output, $error);
if ($error) {
error_log(implode(''n', $output));
return false;
}
return true;
}

因此,变量$file_path[0]不存在。为什么?

我假设$file_path是一个字符串,所以$file_path[0]将访问字符串中的字符元素。

php > $file_path = '/var/www/images/image.gif';
php > print $file_path;    //=> '/var/www/images/image.gif'
php > print $file_path[0]; //=> '/'

如何从动画gif创建静态缩略图?

[0]应该附加到文件路径字符串值,而不是在PHP语言中。

 $file_path .= '[0]';
 //=> '/var/www/images/image.gif[0]'