Skip to content

Commit

Permalink
smush optimization
Browse files Browse the repository at this point in the history
smush and other fixes
  • Loading branch information
alecat88 committed Dec 20, 2017
1 parent 7b414bf commit 16bb3a3
Show file tree
Hide file tree
Showing 10 changed files with 360 additions and 8 deletions.
7 changes: 5 additions & 2 deletions new/assets/js/script.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// JavaScript Document
define(['jquery'],function(){
define(['jquery'],function($){


function close(){
console.log('clicked');
alert('close');
}

$(window).on("load", function() {
$('#preLoader').animate({top:-10450},2000,function(){$(this).hide()});
});
var other = $('#other');
$(document).ready(function(){

//fullscreen
windowWidth= window.innerWidth;
windowHeight= window.innerHeight;
Expand Down
71 changes: 66 additions & 5 deletions new/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Untitled Document</title>
<link rel="stylesheet" href="assets/css/foundationFLEX.min.css">
<link rel="stylesheet" href="assets/css/style.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/jquery.slick/1.5.9/slick.css">
<link rel="stylesheet" href="assets/css/sliderSlickGsap.css">

<style>
#mainSlider{
max-width: none;
Expand Down Expand Up @@ -48,11 +45,71 @@
#mainSlider .slick-list {
height: 50vw;
}
#mainSlider .slider--item, #mainSlider .slick-track{
height: 100%!important;
}
}
</style>
<style>
#preLoader{
position: fixed;
width: 100vw;
height: 100vh;
background: black;
top: 0;
left: 0;
z-index: 999;
display: flex
}
#preLoader svg{
width: 100px;
height: 100px;
margin: auto;
}
#preLoader svg path{
fill: #fff;
}
</style>
</head>
<body>

<div id="preLoader">
<svg version="1.1" id="L7" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 100 100" enable-background="new 0 0 100 100" xml:space="preserve">
<path fill="#fff" d="M31.6,3.5C5.9,13.6-6.6,42.7,3.5,68.4c10.1,25.7,39.2,38.3,64.9,28.1l-3.1-7.9c-21.3,8.4-45.4-2-53.8-23.3
c-8.4-21.3,2-45.4,23.3-53.8L31.6,3.5z">
<animateTransform
attributeName="transform"
attributeType="XML"
type="rotate"
dur="2s"
from="0 50 50"
to="360 50 50"
repeatCount="indefinite" />
</path>
<path fill="#fff" d="M42.3,39.6c5.7-4.3,13.9-3.1,18.1,2.7c4.3,5.7,3.1,13.9-2.7,18.1l4.1,5.5c8.8-6.5,10.6-19,4.1-27.7
c-6.5-8.8-19-10.6-27.7-4.1L42.3,39.6z">
<animateTransform
attributeName="transform"
attributeType="XML"
type="rotate"
dur="1s"
from="0 50 50"
to="-360 50 50"
repeatCount="indefinite" />
</path>
<path fill="#fff" d="M82,35.7C74.1,18,53.4,10.1,35.7,18S10.1,46.6,18,64.3l7.6-3.4c-6-13.5,0-29.3,13.5-35.3s29.3,0,35.3,13.5
L82,35.7z">
<animateTransform
attributeName="transform"
attributeType="XML"
type="rotate"
dur="2s"
from="0 50 50"
to="360 50 50"
repeatCount="indefinite" />
</path>
</svg>
</div>
<?php include ('menu.php'); ?>
<div id="main">
<?php include ('mainSlider.php'); ?>
Expand All @@ -62,6 +119,10 @@
<div class="content"></div>
<img onclick="close()" class="close-game" src="assets/img/close.svg">
</div>
<link rel="stylesheet" href="assets/css/foundationFLEX.min.css">
<link rel="stylesheet" href="assets/css/style.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/jquery.slick/1.5.9/slick.css">
<link rel="stylesheet" href="assets/css/sliderSlickGsap.css">
<script src="assets/js/require.js"></script>
<?php include('requireConfig.php'); ?>
</body>
Expand Down
2 changes: 1 addition & 1 deletion new/requireConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
jquery: 'jquery',
slots: [
'https://vippalace.it/new/slots',
'slot'
'slots'
],
script: 'script',
foundation: 'foundation.min',
Expand Down
254 changes: 254 additions & 0 deletions new/utilities/smush/SmushIt.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
<?php
/**
* Smush.it PHP Library, a simple PHP library for accessing the Yahoo! Smush.it™
* lossless image compressor
* @author Ghislain PHU <[email protected]>
* @version 1.0
*/
class SmushIt
{
/**
* Flag used to preserve objects with errors
*/
const KEEP_ERRORS = 0x01;
/**
* Flag used to throw exceptions when an error
* occurred
*/
const THROW_EXCEPTION = 0x02;
/**
* Internal flag used to notify that the current
* source is a local file
*/
const LOCAL_ORIGIN = 0x04;
/**
* Internal flag used to notify that the current
* source is a remote file (source is an URL)
*/
const REMOTE_ORIGIN = 0x08;
/**
* The base URL of the Yahoo! Smush.it™ API
*/
const SERVICE_API_URL = "http://www.smushit.com/ysmush.it/ws.php";
/**
* Maximum filesize allowed by Yahoo! Smush.it™ API
*/
const SERVICE_API_LIMIT = 1048576; // 1MB limitation
/**
* Error message
* @access public
* @var string | null
*/
public $error;
/**
* Source URI
* @access public
* @var string | null
*/
public $source;
/**
* Compressed image URL
* @access public
* @var string | null
*/
public $destination;
/**
* Filesize of the source image (in Bytes)
* @access public
* @var int | null
*/
public $sourceSize;
/**
* Filesize of the compressed image (in Bytes)
* @access public
* @var int | null
*/
public $destinationSize;
/**
* Saving percentage
* @access public
* @var float | null
*/
public $savings;
/**
* Effective flags
* @access private
* @var int | null
*/
private $flags = null;
/**
* Array of SmushIt objects
* @access private
* @var array
*/
private $items = array();
/**
* Smush.it constructor
* @access public
* @param array | string $sources List of files to compress
* @param int $flags List of flags
* @return object
* @see SmushIt::KEEP_ERRORS
* @see SmushIt::THROW_EXCEPTION
*/
public function __construct($sources, $flags = null)
{
$this->flags = $flags;
$sources = $this->clean($sources);
if (is_string($sources)) {
if ($this->check($sources)) {
$this->smush();
}
} else {
foreach($sources as $source) {
$smush = new SmushIt($source, $flags);
$smushResult = $smush->get();
if (!empty($smushResult)) {
$this->items[] = $smushResult;
}
}
}
}
/**
* Return the list of SmushIt objects
* @access public
* @return array
* @see SmushIt::$items
*/
public function get()
{
return $this->items;
}
/**
* Clean the $sources parameter from SmushIt::__construct()
* (flatten array and remove non-string values)
* @access private
* @param string | array $sources List of files to compress
* @return string | array
* @throws InvalidArgumentException
*/
private function clean($sources)
{
if (is_array($sources)) {
$clean = array();
array_walk_recursive($sources, function($line) use (&$clean) {
$clean[] = $line;
});
$sources = array_filter(array_map(function($line) {
if (!empty($line) AND is_string($line)) {
return $line;
}
}, array_unique($clean)));
} else if (!is_string($sources)) {
$sources = null;
}
if (empty($sources) AND $this->hasFlag(self::THROW_EXCEPTION)) {
throw new InvalidArgumentException('Sources can\'t be empty');
}
return $sources;
}
/**
* Check if source is a readable local file and doesn't exceed filesize limit
* @access private
* @param string $path Location of the current image to compress
* @return bool
* @throws Exception
*/
private function check($path)
{
if ($this->setSource($path) === false) {
$this->error = "$path is not a valid path";
} else if ($this->hasFlag(self::LOCAL_ORIGIN)) {
if (!is_readable($path)) {
$this->error = "$path is not readable";
} else if(filesize($path) > self::SERVICE_API_LIMIT) {
$this->error = "$path exceeds 1MB size limit";
}
}
if (!empty($this->error)) {
if ($this->hasFlag(self::THROW_EXCEPTION)) {
throw new Exception($this->error);
}
return false;
}
return true;
}
/**
* Check if the flag $flag is set in the current object
* @access private
* @param int $flag The flag to check
* @return bool
*/
private function hasFlag($flag)
{
return (bool)($this->flags & $flag);
}
/**
* Set SmushIt::$source and check if it's a local or remote file
* @access private
* @param string $flag The source to set
* @return false | null
*/
private function setSource($source)
{
$this->source = $source;
if (filter_var($this->source, FILTER_VALIDATE_URL) !== false) {
$this->flags |= self::REMOTE_ORIGIN;
} else if (file_exists($this->source) AND !is_dir($this->source)) {
$this->flags |= self::LOCAL_ORIGIN;
} else {
return false;
}
}
/**
* Send current source to the API and get response
* @access private
* @throws Exception
*/
private function smush()
{
$handle = curl_init();
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
if ($this->hasFlag(self::LOCAL_ORIGIN)) {
curl_setopt($handle, CURLOPT_URL, self::SERVICE_API_URL);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, array('files' => '@' . $this->source));
} else {
curl_setopt($handle, CURLOPT_URL, self::SERVICE_API_URL . '?img=' . $this->source);
}
$json = curl_exec($handle);
if ($json === false) {
if (self::hasFlag(self::THROW_EXCEPTION)) {
throw new Exception('Curl error: ' . curl_error($handle));
}
return;
}
$this->set($json);
}
/**
* Set API response data to the current object
* @access private
* @throws Exception
*/
private function set($json)
{
$response = json_decode($json);
if (empty($response)) {
if (self::hasFlag(self::THROW_EXCEPTION)) {
throw new Exception('Empty JSON response');
}
return;
}
$this->error = empty($response->error) ? $this->error : $response->error;
$this->destination = empty($response->dest) ? null : $response->dest;
$this->sourceSize = empty($response->src_size) ? null : intval($response->src_size);
$this->destinationSize = empty($response->dest_size) ? null : intval($response->dest_size);
$this->savings = empty($response->percent) ? null : floatval($response->percent);
if (!empty($this->error) AND $this->hasFlag(self::THROW_EXCEPTION)) {
throw new Exception($this->error);
} else if (empty($this->error) OR $this->hasFlag(self::KEEP_ERRORS)) {
$this->items[] = $this;
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 16bb3a3

Please sign in to comment.