How can I, using PHP, compress an image with Lossy/Lossless compression in a similar way that these two sites compress them:
https://compressor.io/ and https://kraken.io/web-interface
Thanks!
These websites don't compress images using PHP and you can't get a similar result by using PHP - They use different compression tools or plugins written specially to compress images.
To compress a PNG, the best solution is pngquant, but you have to install it on your server to use it with PHP.
Also, here is the list of tools you can check, about the compression of different type of images.
Yes, you can with this PHP API: PHP API for images
It's a set of tools for managing images where lossy optimization is included.
Related
As we all know, it is possible to add/edit effect on a image using php. But can we also do the same thing for a video? I have done some searching for this but no results.
I am giving a link which shows how to show effects on an image and which is working fine, but what about video?
You can do this image effects with GD library.
PHP is not limited to creating just HTML output. It can also be used
to create and manipulate image files in a variety of different image
formats, including GIF, PNG, JPEG, WBMP, and XPM. Even more
convenient, PHP can output image streams directly to a browser. You
will need to compile PHP with the GD library of image functions for
this to work. GD and PHP may also require other libraries, depending
on which image formats you want to work with.
But unfortunately there is no library available in php to Video accessing and adding effects.
I use Imagine library and I would like to know if is it possible to compress images with this library?
Other question:
Do you think it's a good solution to compress a lot (30 images) of images with the library in order to use a command line?
You can save the images with lesser quality to compress them:
To save at 50% quality:
$imagine->open('/path/to/image.jpg')->save('/path/to/image.jpg', array('quality' => 50));
And as for whether or not to do the compression at command line, you can do it but I don't recommend it. Image manipulation takes a lot of cpu and ram, so I suggest you download the images and manipulate them on your computer (not on the production server), or do it in a php script but limit the number of images to compress.
I want to use compression so that i can speedup my website.Which is the best compression available? Is compression using ob_start("ob_gzhandler"); the best? Does it compress the images embedded.Is there a way to compress those images?
P.S: I don't have access to the server configuration. I only have a FTP account
I would suggest you use the webserver's functions for that. If you use apache, you can check out http://httpd.apache.org/docs/2.0/mod/mod_deflate.html for instance.
Yes, ob_start("ob_gzhandler") is the best you can get if you don't control the server.
The difference between various methods is mainly in efficiency, e.g. some servers or reverse proxies are able to cache compressed data to avoid re-compressing them again. However, gzip is very fast for today's hardware, so even most basic compression in PHP is going to be a net gain.
You should also compress your JS and CSS files, but you shouldn't do that by simply wrapping them in a PHP script, because by default PHP makes files non-cacheable. Any gain from compression will be lost when browsers are forced re-download those files over and over again.
Ideally you should either use a CDN that will compress them for you or ask your host to enable server-level compression for static text files.
No, ob_gzhandler doesn't compress images if you just provide a link in your HTML. Only if you load them into a PHP file as binary data, like with file_get_contents().
I process uploaded images by php to save (after resize) by imagejpeg. As I explored, imagejpeg is the best php command to compress jpg images to reduce the file size. However, when I check my website by Google Page Speed, it says all of my images can be compressed 4-10%.
What is the common method to compress images to meet the Google standard?
Googles "standard" is the possible maximum to be expected by google. You need to use highly optimized image compressors that does nothing else than image compressing and therefore get a possible maximum best value here.
You can for example, open you jpeg file in a image editor like adobe photoshop and create the possible maximum best compression to be expected by you while having visual control. Highly recommended.
The GD library provides a standard conform jpeg compression which should match a library users expectation, but which might not satisfy a graphic designer (and/or google by 4-10%).
Does anyone know about a PHP library which can produce layered PNG images? (I'm not sure, but I think that tiff image standard supports layers also)
AFAIR, PNG does not support layers. MNG does and you can produce these with ImageMagick. For PHP extension see: http://www.php.net/imagick
From the ImageMagic API site:
PHP
MagickWand for PHP a native PHP-extension to the ImageMagick MagickWand API.
IMagick is a native PHP extension to create and modify images using the ImageMagick API. Documentation for the extension is available here.
phMagick is a wrapper class for ImageMagick, wrapping the most common web image manipulation actions in easy to use functions, but allowing full access to ImageMagick's power by issuing system calls to it's command-line programs.
ImageMagick® is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.
Assuming you mean the layered PNG files as per fireworks, I don't think you can do it. I've not seen anything except fireworks that supports these files properly.