Skip to content

Commit

Permalink
Version 1.4.0 - add AVIF support
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon committed Dec 12, 2020
1 parent f882521 commit 6e9cbdb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lib/ShortPixelWeb.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
namespace ShortPixelWeb;

//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);

use ShortPixel\persist\TextPersister;
use ShortPixel\SPLog;
Expand All @@ -15,7 +18,7 @@

class ShortPixelWeb
{
const VERSION = "1.3.3";
const VERSION = "1.4.0";
const DEBUG_LOG = false;

private $settingsHandler;
Expand Down Expand Up @@ -225,7 +228,8 @@ function renderSettings($type) {
$this->xtpl->assign('resize_checked', \ShortPixel\ShortPixel::opt('resize') ? 'checked' : '');
$this->xtpl->assign('width', \ShortPixel\ShortPixel::opt('resize_width'));
$this->xtpl->assign('height', \ShortPixel\ShortPixel::opt('resize_height'));
$this->xtpl->assign('webp_checked', \ShortPixel\ShortPixel::opt('convertto') == '+webp' ? 'checked' : '');
$this->xtpl->assign('webp_checked', strpos(\ShortPixel\ShortPixel::opt('convertto'), '+webp') !== false ? 'checked' : '');
$this->xtpl->assign('avif_checked', strpos(\ShortPixel\ShortPixel::opt('convertto'), '+avif') !== false ? 'checked' : '');
$this->xtpl->assign('resize_outer_checked', \ShortPixel\ShortPixel::opt('resize') & 2 ? '' : 'checked');
$this->xtpl->assign('resize_inner_checked', \ShortPixel\ShortPixel::opt('resize') & 2 ? 'checked' : '');
}
Expand Down Expand Up @@ -294,7 +298,7 @@ function renderOptimizeNow($optData) {
&& ( $status->total == $status->succeeded + $status->failed
|| isset($status->todo) && count($status->todo->files) == 0 && count($status->todo->filesPending) == 0)) {
//success
$this->xtpl->assign('total_percent', number_format(100.0 - 100.0 * $status->totalOptimizedSize / $status->totalSize, 2));
$this->xtpl->assign('total_percent', $status->totalSize ? number_format(100.0 * (1 - $status->totalOptimizedSize / $status->totalSize), 2) : 0);
$this->xtpl->assign('total_files', $status->total);
$this->xtpl->assign('succeeded_files', $status->succeeded);
$this->xtpl->assign('failed_files', $status->failed);
Expand Down
13 changes: 11 additions & 2 deletions lib/ShortPixelWeb/tpl/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,18 @@ <h2 style="margin: 40px 0 10px">{options_type} optimization options:</h2>
<div class="options-line">
<label>WebP versions</label>
<div class="form-field">
<input class="webp" id="webp" type="checkbox" name="webp" {webp_checked}> Create also <a href="http://blog.shortpixel.com/how-webp-images-can-speed-up-your-site/" target="_blank">WebP versions</a> of the images <strong>for free</strong>.
<input class="webp" id="webp" type="checkbox" name="webp" {webp_checked}> Also create <a href="http://blog.shortpixel.com/how-webp-images-can-speed-up-your-site/" target="_blank">WebP versions</a> of the images.
<p class="settings-info">
WebP images can be up to three times smaller than PNGs and 25% smaller than JPGs. Choosing this option <strong>does not use up additional credits</strong>.
WebP images can be up to three times smaller than PNGs and 25% smaller than JPGs. Choosing this option <strong>will use an additional credit for each generated WebP image</strong>.
</p>
</div>
</div>
<div class="options-line">
<label>AVIF versions</label>
<div class="form-field">
<input class="avif" id="avif" type="checkbox" name="avif" {avif_checked}> Also create <a href="http://blog.shortpixel.com/how-webp-images-can-speed-up-your-site/" target="_blank">AVIF versions</a> of the images.
<p class="settings-info">
AVIF images can be up to four times smaller than PNGs and 40% smaller than JPGs. Choosing this option <strong>will use an additional credit for each generated AVIF image</strong>.
</p>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion webroot/js/sp-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
$("#width").val(options.resize_width);
$("#height").val(options.resize_height);
$("#resize_type_" + (options.resize & 2 ? 'inner' : 'outer')).prop("checked", true);
$("#webp").prop("checked", (options.convertto == '+webp' ? true : false));
$("#webp").prop("checked", (options.convertto.indexOf('+webp') >=0 ? true : false));
$("#avif").prop("checked", (options.convertto.indexOf('+avif') >=0 ? true : false));
$("#exclude").val(options.exclude);
$("#backup_path").val(options.backup_path);
$('<div class="specific-options-msg"><h3 class="success" id="info-message">Folder-specific options loaded, please check below.</h3>' +
Expand Down

0 comments on commit 6e9cbdb

Please sign in to comment.