Pngquant has the following example for php
// '-' makes it use stdout, required to save to $compressed_png_content variable
// '<' makes it read from the given file path
// escapeshellarg() makes this safe to use with any path
$compressed_png_content = shell_exec("pngquant --quality=$min_quality-$max_quality - < ".escapeshellarg( $path_to_png_file));
I want to replace $path_of_file
with the actual content.
This will avoid wasting I/O when converting a file from one format to png and then optimize it
What will be the new shell_exec()
command in that situation
I am no PHP expert, but I believe you are looking for a 2-way pipe (write and read) to another process, so that you can write data to its stdin and read data from its stdout. So, I think that means you need
proc_open()
which is described here.It will look something like this (untested):