I have been searching for an alternative to ffmpeg (I'm on a host that doesn't allow ffmpeg or mencode due to server power or something) and I was looking into GD or Imagemagick (both of which are installed) is there a way to generate a video thumbnail from either of these two libraries or another one?
I also have the option of using ruby on rails or python or CGI/perl to do the generation. But I'm not skilled in either of those languages so I would need a tutorial or script already wrote.
Anyone help?
Imagemagicks Convert can do video tumbnails.
convert -quiet moviefile.mov[10] movieframe.gif
where the number between the [] is the framenumber of the movie that is converted
In fact, ImageMagick just uses ffmeg under the hood. If ffmpeg is not installed, you'll have no luck using ImageMagick
As tijej said you must need ffmpeg in order to use ImageMagick. If you are OK with that you can also use FFmpeg::Thumbnail module.
Sample:
my $baz = FFmpeg::Thumbnail->new( { video => '/my/video/file.flv' } );
$baz->output_width( 640 );
$baz->output_height( 480 );
$baz->offset( 21 );
$baz->create_thumbnail( undef, '/my/first/thumbnail.png');
Related
I'd like to use imagemagick to make a montage from existing photos on my server. I am having a terrible time getting any code to work properly. I've tried using the few examples I've found by searching, but it's not working.
http://us1.php.net/imagick outlines the library beautifully, but there are no montage examples. I'd just need a proper example to get me off on the right foot and I' can usually take it from there.
Does anyone know of a good resource to learn imagick for PHP?
Here is a working example of montageImage. The example does a color analysis of a photo. To make sure it works properly, you will need to make sure:
You have a valid "test.png".
Imagick::clone has been deprecated as of imagick 3.1.0 in favour of using the clone keyword. So if you have imagick 3.1.0, you will need to change lines 13 and 17.
$bright = $average->clone();
to
$bright = clone $average;
and
$dark = $average->clone();
to
$dark = clone $average;
Good luck.
Did you start with the basic example?
http://us1.php.net/manual/en/imagick.examples-1.php
I am generating PNG file with cairo extension of PHP. The image contains a background and a text. Now I want to compress these images by PHP after its generated by cairo. Is there any library to do this?
I found pngcrush tool. But its a command line tool. I dont want to invoke system call. If there is not PHP solution a C solution would do. In that case I'll make a PHP extension.
I have read this related question. But there is no answer in it.
You can use imagepng() ...
//If you don't already have a handle to the image and it's just on the file system...
$im = imagecreatefrompng("yourGenerateFile.png");
$quality = 5; //0 - 9 (0= no compression, 9 = high compression)
imagepng($im, 'file/to/save.png', $quality); //leave out filename if you want it to output to the buffer
imagedestroy($im);
I would take a look at PngOptimizer. You can get the source for it at the bottom of the page, and it has a separated CLI version too.
Only problem is that source is C++ , not ANSI C. I have never made a PHP extension, so i don't know if it makes a difference.
For C code take a look at ImageMagick. It looks like there is a PHP extension too.
I need to convert single Powerpoint (PPT) slides/files to JPG or PNG format on linux but haven't found any way of doing so successfully so far. I have heard that it can be done with open office via php but haven't found any examples or much useful documentation. I'd consider doing it with python or java also, but I'm unsure which route to take.
I understand that it can be done using COM on a Windows server but would really like to refrain from doing so if possible.
Any ideas/pointers gratefully received. (And yes, I have searched the site and others before posting!)
Thanks in advance,
Rob Ganly
Quick answer (2 steps):
## First converts your presentation to PDF
unoconv -f pdf presentation.ppt
## Then convert your PDF to jpg
convert presentation.pdf presentation_%03d.jpg
And voilá.
Explaning a little more:
I had already follow in the same need. Convert a powerpoint set of slides into a set of images. I haven't found one tool to exactly this. But I have found unoconv which converts libreoffice formats to other formats, including jpg, png and PDF. The only drawback is that unoconv only converts one slide to a jpg/png file, but when converting to PDF it converts the whole presentation to a multiple page PDF file. So the answare were convert the PPT to PDF and with imagemagick's convert, convert the multiple page PDF to a set of images.
Unoconv is distributed within Ubuntu distribution
apt-get install unoconv
And convert is distributed with the imagemagick package
apt-get install imagemagick
In my blog there is an entry about this
This can be done from PHP using a 3d party library (Aspose.Slides). It will work on both .ppt and .pptx, and it's lightning fast.
Here is the relevant piece of code in PHP:
$runtime->RegisterAssemblyFromFile("libraries/_bin/aspose/Aspose.Slides.dll", "Aspose.Slides");
$runtime->RegisterAssemblyFromFullQualifiedName("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing");
$sourcefile = "D:\\MYPRESENTATION.ppt";
$presentation = $runtime->TypeFromName("Aspose.Slides.Presentation")->Instantiate($sourcefile);
$format = $runtime->TypeFromName("System.Drawing.Imaging.ImageFormat")->Png;
$x = 0;
/** #var \NetPhp\Core\NetProxyCollection */
$slides = $presentation->Slides->AsIterator();
foreach ($slides as $slide) {
$bitmap = $slide->GetThumbnail(1, 1);
$destinationfile ="d:\\output\\slide_{$x++}.png";
$bitmap->Save($destinationfile, $format);
}
$presentation->Dispose();
It does not use Office Interop (which is NOT recommended for server side automation) and is lightining fast.
You can control the output format, size and quality of the images. Indeed you get a .Net Bitmap object so you can do with it whatever you want.
The original post is here:
http://www.drupalonwindows.com/en/blog/powerpoint-presentation-images-php-drupal-example
I want to be able to detect whether an image is transparent or not using the Imagick PHP extension.
So far, the only luck I've been having is to run the exec() / some other command, and use the ImageMagick command line tool to achieve this. Here's what I mean:
exec("identify -verbose example_transparent_image.png | grep \"Alpha\"", $output);
$is_transparent = !empty($output) ? true : false;
The logic is simple. Do a verbose check on the image in question: if the output contains any alpha information, that means it uses transparency.
It seems that the PHP imagick extension should have this as one of its commands, but the lack of documentation is killing me. It seems silly to have to run this kind of check each time.
Ahhh, solved (I think). Imagick has a function getImageAlphaChannel() which returns true if it contains any alpha information and false if it doesn't.
Make sure you have ImageMagick 6.4.0 or newer.
http://www.php.net/manual/en/function.imagick-getimagealphachannel.php
Maybe this
http://ru.php.net/manual/en/function.imagick-identifyimage.php
What's about this?
substr((new Imagick($FILE))->identifyImage()['type'], 0, -5) == 'Alpha'
look at the documentation of identifyImage. You will notice the missing documentation of the functions output. It's just a parsed version of
identify -verbose $FILE (from the imagick package)
where type identifies the image's type (compare source).
You can see that imagick returns the value from some MagickTypeOptions array which is defined here. This array contains an -Alpha and -Matte version for every image type if it's color palette contains alpha.
Theoretically you could save an image with such palette without using it, but every decent programm should swith to the non-alpha version in this case. But false positives are possible but should be rare.
Also I don't check for the -Matte image types because in the array is defined in a way that for every image type constant there are two entries with different names (-Alpha and -Matte), but as -Alpha comes first this name will be returned for that image type.
Is there a built-in function in php to add some extra sharpness on images? Like Photoshops unsharp mask?
Yes, the easiest way is to use the phpThumb library. Here is a demo of the sharpen feature:
http://phpthumb.sourceforge.net/demo/demo/phpThumb.demo.demo.php#x14
You can apparently also use imageconvolution() in the GD library (phpThumb uses either GD or ImageMagick, whichever is available):
http://www.php.net/manual/en/function.imageconvolution.php