mass image optimizer - php

I have a folder with about 5000 images in it.
I can use php, or software on a local version of the images if required.
Whats the best way to go through and optimize/shrink their size/compress them as quickly and efficiently as possible to 20 width and 20 height?
Anything with a GUI that works on XP?

Tools like mogrify or convert (from ImageMagick) will do just fine, when it comes to resizing images.
After, if you want to optimize your images further (reducing their size in bytes), you should take a look at software like :
optipng or pngcrush for PNG,
or jpegtran for JPEG
If your goal is optimization for a website, take a look at Best Practices for Speeding Up Your Web Site - Images and the points which follow (I'm especially thinking about CSS Sprites)
Edit after edit of the OP : hu... a GUI ? No idea, sorry (I have those kind of tools run automatically, from scripts, on Linux servers).
Why not just write a script that will call those tools on all your images, and let it run for the night ?

Use either of imagemagick or GD2 .. GD2 is already bundled in the newer versions (5.0+) of PHP. This way, you won't have to install new extension.

This tutorial is what you are looking for.

Related

Converting PPTX to PDF with PHP

I am developing an API, in PHP, hosted on a linux server, that requires me to make jpeg previews for a .pptx powerpoint presentation.
I first convert the file to pdf and then convert the pdf to jpegs.
The second step is easy, with ghostscript, it's the first part that's proving difficult.
I have tried using the libreoffice executable, but pptx isn't completely compatible. Certain backgrounds become invisible.
I have the same problem with many 3rd party APIs (which I suspect also use libreoffice); the ones that do work, are ridiculously expensive.
Installing office on a Linux server and using COM functions seems impossible, or very tedious at best.
I have looked at Aspose.Slides, which also seems rather expensive, and their documentation is filled with errors.
I could use suggestions on how to tackle this problem.
I have tried to find the underlying problem of why LibreOffice and online conversion tools have a problem with the backgrounds of the presentations I need to convert.
The background is a .emf file, which has bad support.
My solution
I've unzipped the presentation, converted the .emf files to png (using ghostscript), changed all mentions of .emf to .png in the XML, and rezipped the altered presentation.
When I now use the LibreOffice headless to convert to pdf, the background shows up.
It might be a bit hacky, but it works for the intent of my program.
ps. I see that my question has gathered a few downvotes. In my opinion it was a valid question, and listed the various solutions that had worked for others, but not for me. If anyone has insights or ways to improve it, feel free to comment.

PHP Image Optimize without EXEC

I want to optimize a JPG image (lossless compression) to satisfy Google Page Speed, but I do not want to use this function:
exec("someBashCommand")
Every script that I found uses this function, but it is banned on my server.
Is it possible to do with pure PHP?
You can use ImageMagick with PHP, like this:
<?php
$img = new Imagick("image.jpg");
$img->setImageCompression (imagick::COMPRESSION_LOSSLESSJPEG);
$img->writeImage('result.jpg');
?>
but I have no idea how it is likely to help optimise anything if you are not prepared to allow some degree of quality tradeoff for size.
You could install the PageSpeed Module on your server:
https://developers.google.com/speed/pagespeed/module
but I am afraid that's also banned on your server.
But know that you don't have to optimize images ON your server, you can do it BEFORE you upload the images to the server. The only exception would be images uploaded by users of your website.
Use any image program with enough options for saving images to imitate what Google wants you to do. There's nothing mysterious about it, it can all be done in normal software. For instance:
http://www.practicalecommerce.com/articles/71090-15-Tools-to-Optimize-Ecommerce-Images
But remember these packages may not satisfy Googles demands.
Do not overdo this. Google shows you the best possible optimization, according to the rules they set, but your site will work fine even if Google thinks it could be slightly better.

Imagemagick exec and convert

I recently started using imagemagick with php and
I'm relatively new with both of these, IM and PHP.
So, I'm here to ask for some help/suggestion(s).
First
If lets say a user uploads a gif or a png image on
my site and I want it converted to jpg, is there any
command like for example.$image->convert($file,'.jpg)
or the convert command is accesible only thru exec() ?
like for example exec(convert picture.png to picture.jpg)
Second
What if for again, the user uploads gif/png on the site
and I resize the image to a specified width/height and
write the image, with the writeImage function of IM like this:
$image->writeImage(basename.$ext) where $ext = jpg.
Will this work properly,is this a good practice? I assume this will
only rename it but still, I don't see a problem in this... o.O
Oh sorry one more question, I'm not very familiar with exec,
is it better using imagemagick using exec(), does it improve
speed, load etc?
I can't answer your questions directly but thought I point you to a few resources:
Regarding which is better, exec or the PHP extension, I asked this same question a few months ago:
Should I use a PHP extension for ImageMagick or just use PHP's Exec() function to run the terminal commands?
For all Image Magick PHP functions you should look up the official guide:
http://www.php.net/manual/en/book.imagick.php
I switched from Image Magick to Graphics Magick as I heard it has better performance. It is a fork of Image Magick with an emphasis on performance. Large sites like Flickr and Etsy use it:
http://www.graphicsmagick.org/
This guide got me started:
http://devzone.zend.com/1559/manipulating-images-with-php-and-graphicsmagick/
And they have their own manual on php.net:
http://php.net/manual/en/book.gmagick.php (most of the commands are identical to Image Magick's)
I prefer using exec() as it is supported a lot better than Imagick ( the example code you posted ), easier to use and supports all the operators ( depending on your version ) which again Imagick does not.
Some of the Imagick code works differntly in the different versions; there are a lot more Imagick examples around than there were a couple of years ago when I first started looking at it.
Saying that Imagick can be faster and is/can be? built into php although some people have trouble installing it.
I belive that this site http://valokuva.org/?cat=1 belongs to a Imagick developer and has lots of examples.
My site www.rubblewebs.co.uk/imagemagick has lots of examples of php with exec( )
As to your other two questions yes you can change the file type with Imagick and I am not sure about basename.$ext - why not try it? As long as basename does not have an extension it may work but you might need to include basename.$ext in quotes.
As to speed it dpends sometimes GD is faster other times Imagick or Imagemagick. You can always do some tests. I did some a year or so ago and you can try the code on your server. http://www.rubblewebs.co.uk/imagemagick/speed/Speed_tests_1.pdf

Using Photoshop Actions on Images uploaded by Users

I want to have a user upload a image to my website and have a series of Photoshop actions like adding a layer behind of that image, a layer infront and some dynamic text with effects applied to it like drop shadow and gradient overlay. Is this even possible?
Have a look at Various Image Processing and Generation functions provided by PHP mainly ImageMagick & GD. If that does not prove to be sufficient,
Consider Gimp command line. you can easily invoke it from php using exec() function. GIMP is full featured & can do almost all fancy Photoshop actions you would want. And its free!
Hope it helps
PHP libraries are available to perform some basic graphics manipulation, as mentioned in the other answer. If these aren't adequate for you, it looks as though you can run and script the normal Photoshop program on your server. Photoshop is not available for Linux, so you'd probably need a Windows server. (This wouldn't be doable on shared hosting, you'd probably need a decent VPS at least.)
I haven't done this before, but according to Adobe Photoshop Scripting documentation your language choices are JavaScript and VBScript. Someone could write a PHP library to access this, but I don't know of anything like that.

PHP rotate video

I have my own video sharing app,
My question is... is there any library,script or something else, to help me in rotating videos whatever their file extension is?
Many peoples are uploading videos but sometimes i found video (guessing shared with iphones or mobile phones) and i see them horizontally instead of vertically...
Does anyone have any ideas how to rotate them dynamically?
Im not familiar with any "libraries" that will do that. I think your better bet would be to find a command-prompt-enabled video software package (like Any Video Converter [See Q7]) that PHP can execute via command prompt on the fly.
PHP doesn't do that, and there are no extensions that I know off, made for that purpose.
You can use ffmpeg to manipulate videos, by calling it from your scripts (see shell_execute() and such functions). Reading the ffmpeg documentation will help you figure what can (and can't) be done with that powerful tool.

Categories