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

Imagemagick: can not make a static thumbnail from gif animation

我使用 jQuery-File-Upload 脚本。该软件包还包含一个 php 脚本,用于处理文件和制作缩略图。一切正常,但如果用户上传动画 gif 文件,我需要创建静态缩略图。

下面是创建缩略图的函数。

我已经注释掉了 "Handle animated GIFs:" 的所有内容,因为我不想要动画 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;

}

So, the variable $file_path[0] does not exist. Why?

我假设 $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]; //=> '/'

How can I create static thumbnails from animated gifs?

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

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