Best way to create thumbs

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
forumwt
Posts: 1
Joined: 2013-05-13T16:17:47-07:00
Authentication code: 6789

Best way to create thumbs

Post by forumwt »

Hello

I have a tube site and im using this function to generate thumbs from video file

Code: Select all

$thumbwidth = 240; //thumb width
$thumbheight = 180; //thumb height

$imagick_command = "-modulate 110,102,100 -sharpen 1x1 -enhance";

shell_exec("$ffmpeg_path -ss $first -i \"".$row[file]."\" -vcodec mjpeg -vframes 1 -an -f rawvideo -s ".$thumbwidth."x".$thumbheight." \"$image\"");

shell_exec("/usr/local/bin/mogrify $imagick_command $image"); 
Here is thumbs result, this image is just what i need, no border and etc..

Image

but sometimes depending on video i have thumbs like this

Image

Whats the best way to remove this black space from thumbs, but need to keep thumb size 240x180
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Best way to create thumbs

Post by fmw42 »

You will have to live with the black if you want to keep the size the same, unless you trim the black and then resize to fill the vertical dimension and then crop the excess from the horizontal. You can also trim and resize to the exact dimensions you want, but then the image will be distorted because it does not then keep the aspect ratio.

The problem may be that you are extracting a frame from an animation that has been optimized. You may want to coalesce the animation frame(s) before making thumbnails.

see
http://www.imagemagick.org/Usage/anim_basics/#coalesced
http://www.imagemagick.org/Usage/anim_mods/#mods
http://www.imagemagick.org/Usage/anim_opt/
http://www.imagemagick.org/Usage/anim_basics/
Post Reply