I found out that images can be compressed by a certain percentage. For example:
$compressed_img = compress($source_img, $destination_img, 90);
In this case, the size of $source_img
will be reduced to 90% of the original size.
If the original size is of $source_img
100kb, that of $compressed_img
will be 90kb.
What I've been trying to do is to determine whether the target file is compressed based on the original size, and determine how much size is going to be reduced by byte.
For example, what if you need to ensure that all the uploaded files are under 200kb but you must not change the size if the uploaded size is already lighter than that?
Here is a pseudo code.
if($source > 200kb){
$compressed = compressByByte($source, 200kb);
}//Again, this is a sude code!
Since the size of the source file varies, it's not going to be practical to use the compress()
function.
Any advice will be appreciated. (I'm using php with Laravel 5.2)