Where can I find comprehensive image manipulation library information? - php

I've spent a lot of time Googling and searching SO for information on image manipulation libraries with little success. Please direct me if this has been answered before and I just can't find it.
Basically I'm trying to resize an arbitrarily sized image to a couple of smaller thumbnail images, say 400px wide and 200px wide while maintaining the original aspect ratio. The original image is being uploaded via php (linux) and I've found that I can use Cairo, GD, GMagick, or ImageMagick but I've been unable to find comprehensive data on which is better suited for image manipulation. I have found comparisons for image creation, but that's functionality I won't be using.
I also have the option of uploading via php then performing the image manipulation via another method (perl/python/etc, for example) if that proves better suited.
Any pointers in the right direction are appreciated. Quality is my primary motivation followed by output image file size then library performance.

GD and ImageMagick are your best bets, so get some representative images and run some tests using:
imagecopyresampled() for GD
Imagick::thumbnailImage() for ImageMagick
Imagick::resizeImage() if you want more control and to try a few filter constants.
Resizing images in PHP with GD and Imagick has some code samples to get you going.
Compare them visually and by filesize. If there's no obvious winner, then run some benchmarks based on your expected needs. How to benchmark efficiency of PHP script is a good reference point.
Also take a look at:
Choosing between Imagemagick & GD for thumbnail creation
Should I use ImageMagick or GD2 with ImageAPI in Drupal?

Related

Obtaining video information using FFMPEG, or possibly HTML5

I'm making a video gallery and would like to pull some info about the video for displaying. Does anyone know how I would go about retrieving the video duration using ffmpeg? Is it possible to get this info using HTML5?
Thanks.
What I do (on Linux) is this:
tcprobe -i $FILE | tail -n1 | cut -d '=' -f3
tcprobe is from the transcode Debian package.
If you're on Windows there's a tool called MediaInfo, but I haven't tried it so I can't remark on its effectiveness.
Use exec function in php
http://www.longtailvideo.com/support/forums/jw-player/setup-issues-and-embedding/9448/how-to-get-video-duration-with-ffmpeg-and-php
I would recommend PHPVideoToolkit...
This class is a wrapper around the
FFmpeg, FLVTools2 and Mencoder
programs to allow PHP developers to
manipulate and convert video files in
any easy to use object oriented way.
It also currently provides FFmpeg-PHP
emulation in pure PHP so you wouldn't
need to compile and install the
module. Note, it isn't intended as a
FFmpeg-PHP replacement, only an
alternative solution and it is
recommended that if you make heavy use
of the FFmpeg-PHP functionality you
should install the module as it is
more efficient.
PHPVideoToolkit is pretty much the
only video/audio class that you will
need from now on. It performs several
types of manipulation operations that
include video format conversion,
extract video frames into separate
image files, assemble a video stream
from a set of separate video images,
extract audio from video, watermark
videos and extracted frames. Several
parameters can also be configured like
the output video file format (which
can be Flash video or any other
supported by ffmpeg), video and audio
bit rate and sample rate, video
dimensions and aspect ratio. It can
also retrieve information about the
media file, such as duration, bitrate,
framerate, format, dimensions, display
aspect ratio, pixel aspect ratio,
audio stereo, audio frequency and
audio format, without any other
additional library such as ffmpeg-php.
Note, I wrote it so ask any questions you want about using it.

PNG compression with PHP magickwand

I'm wondering how to compress an PNG image correctly.
The situation is this :
I have a PNG image compressed and color-reduced with Irfanview on Windows. It's about 20KB.
When my portal software resizes (using magickwand 1.0.7) it with default values, it's about 63K (!).
Next try was to call MagickSetImageDepth($this->_imageHandler,8), resulting in a filesize of 34K, which is better, but still it's bigger than the (larger in dimension) original file.
None of the documented functions seem to fit to further compress the image.
Any hint would be greatly appreciated !
Greetz,
Sosa
PNG compression programs and routines use different techniques. I've found out that many times, an image that's already been compressed (or saved efficiently) cannot be compressed further or even has a higher file size as you are experiencing.
In your case I'd say your images cannot be compressed further, at least using MagickWand. You might just want to leave out that step.
Perhaps optimizing your PNGs before runtime would be a solution. There are many options available in this case. I've had luck with PNGGauntlet. You can run a batch job on PNGGauntlet and it will skip over the files that it would've made larger, if any.
Try this tool by Yahoo - it's great!
http://developer.yahoo.com/yslow/smushit/

PHP Replace Images with GD Library Resampled Images in Joomla

I am the tech intern for an online independent newspaper, and the writers on the staff are not tech-savvy. They don't quite understand how web pages work, and often they upload and include images straight from their digital cameras, or scanned from original media. These images become a burden when there are 10 images on the front page each at 3.5Mb each.
We are trying to work out some sort of training method for teaching them how to resize and optimize the images they want to include in their articles, but like I said, they are not very tech savvy, and any method we attempt to employ may go way over their heads.
So, I wanted to know if it is outside of reason to attempt to resample and cache images that are included in the articles using a PHP function and the GD library in order to stream line the amount of data that has to be passed per article.
I think it's possible, I'm just trying to figure out if it would be worth it to just take the time and effort to train the writers, or if creating an automated process would be better.
You'd be better off doing the GD image processing during the upload process. GD can take up quite a bit of resources, so processing each image on every request would not be a preferable solution. If you can't do it during the upload process, you should cache all the resampled images and use those if/when available.
It's certainly possible, and I'd be very surprised if Joomla! doesn't already have modules that do just that.
With the current web site that I'm working on I needed to answer a similar question. I've opted for using the joomla addon Easy Gallery. The two stand out features for me are the automated thumbnail creation and the image resize feature. The sizes are configurable with the components configuration page. You'll have a thumbnail, a resized image and the original image with each upload.
This component is a Joomla 1.0 component, so, if you're running a Joomla 1.5 install you will need to turn on legacy mode. Work seems to be in progress for a native 1.5 version.
I also found a couple of places where the generated thumbnails weren't being displayed. I raised the question on the Easy Gallery forum, and managed to work out the answer for myself.

How to perform seam carving on an image using PHP's GD library?

I am working on a project that resizes images using PHP's GD library. I would like to be able to add the option to use seam carving to resize images but don't want to require something like ImageMagick (which can do seam carving with its liquid rescale feature) to accomplish this.
Since there are no built-in seam carving functions in GD, is there a way to perform seam carving on an image using PHP's GD library or other built-in PHP functions? Alternatively, do you know if seam carving will eventually be baked into GD?
While you could implement this using GD, you're best bet if you can control the server environment is to create an external script/program to carve an image. PHP is going to be a huge bottleneck doing those kind of calculations. Even basic matrix transformations run a serious risk of hitting the max execution times set in PHP configs.
I don't see why it shouldn't be possible with GD, but I can tell you it would be slow.
Imagemagick is open source, so I guess you could translate the function to PHP.

PHP Thumbnails

I was looking at a way to dynamically create thumbnails using PHP and GD but everytime i select a large image maybe 10MegaPixels about 4-5MB it gives the error
**images/Surabhi_Cow.jpgimages/tn/Surabhi_Cow.jpg
Fatal error: Allowed memory size of 31457280 bytes exhausted (tried to allocate 10368 bytes) in C:\Program Files\xampp\htdocs\MySite\Staff\test.php on line 51**
Changing the memory_limit in php.ini to 60 does the trick but my host only allows the memory_limit to 32M. What other options do I have to generate thumbnails on the fly?
I checked phpThumb() but don't really get it. So any other options are welcome!
You want to use ImageMagick. It is much more efficient in handling large images than GD.
If all you want to do is generate thumbnails. I recommend this nice little script called imagethumb.php. You can download it here:http://www.olivo.net/software/imagethumb/
This script produces excellent thumbnails with absolutely no pixelation. It accepts a height or width argument that you append to the URL that calls the script. It's really really easy to use and comes with documentation (which you'll read for all of 2 minutes).
I tried other thumbnailing scripts such as "ThumbsUp" (for example) before landing on this one. BTW, it also renders .png images and also .gif (if I recall correctly). The cache feature will make it easier on your server if you have large files. Also, I assume that your server has the GD library or ImageMagick installed. Good Luck ;)
As the others have said, if the images are that big it's time to drop GD and switch to ImageMagick. One word of warning though: do it all on the command-line - the class wrappers out there are wheels in need of damn good re-inventing, every last one.
Consider using a command-line based approach. For example, you can invoke ImageMagick from the command-line to resize images.
Other than that, in pure PHP, it's hard to see how you can edit images that are larger (in RGB format) than your RAM...
I was doing some research on the topic and I found Imagick much more efficient for manipulating bigger images. You`ll either pass the allowed memory or the maximum execution time. A better approach would be to use Imagick library. Check the onfo on how to generate thumbnails with php on the fly using Imagick.

Categories