(no comment)

This commit is contained in:
John Alanbrook 2022-11-08 22:59:19 +00:00
parent 9f6302fa48
commit d3eb3720f7

View file

@ -183,11 +183,11 @@ function p_img($src, $opts, $ext) {
/* Given a source image and options, creates the appropriate images /* Given a source image and options, creates the appropriate images
* jpeg, webp, and avif for lossy, and png and lossless webp for lossless * jpeg, webp, and avif for lossy, and png and lossless webp for lossless
*/ */
function gen_images($src, $opts = "") { function gen_images($src, $opts = "", $lossy=0) {
$psrc = ltrim($src, '/'); $psrc = ltrim($src, '/');
$path = pathinfo($psrc); $path = pathinfo($psrc);
if (in_array($path['extension'], ["jpg", "jpeg"])) { if ($lossy || in_array($path['extension'], ["jpg", "jpeg"])) {
$je = ltrim(p_img($src, $opts, "jpg"), '/'); $je = ltrim(p_img($src, $opts, "jpg"), '/');
$jpath = pathinfo($je); $jpath = pathinfo($je);
@ -205,6 +205,8 @@ function gen_images($src, $opts = "") {
if (!file_exists($ae)) { if (!file_exists($ae)) {
`convert -quality 80 $opts $psrc $ae`; `convert -quality 80 $opts $psrc $ae`;
} }
return;
} }
@ -216,17 +218,20 @@ function gen_images($src, $opts = "") {
`mkdir -p $genp`; `mkdir -p $genp`;
if (!file_exists($we)) { if (!file_exists($we)) {
`convert -quality 80 -define webp:lossless=true $psrc $we`; `convert -define webp:lossless=true $opts $psrc $we`;
} }
return;
} }
} }
function make_img($src, $opts="", $q=80) { /* If lossy is true, makes lossless images lossy; does nothing for already lossy images */
function make_img($src, $opts="", $lossy=0) {
$p = img_src($src); $p = img_src($src);
gen_images($p, $opts); gen_images($p, $opts, $lossy);
if (pathinfo($p)['extension'] == "png") { if (!$lossy && pathinfo($p)['extension'] == "png") {
$pe = $p; $pe = $p;
$we = p_img($p, $opts, "webp"); $we = p_img($p, $opts, "webp");