%PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY
| Server IP : 14.207.165.8 / Your IP : 216.73.216.14 Web Server : Apache/2.4.18 (Ubuntu) System : Linux 246 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : root ( 0) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : exec,passthru,shell_exec,system,proc_open,popen,pcntl_exec MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/old/modules/mod_image_show_gk4/ |
Upload File : |
<?php
/**
* @author: GavickPro
* @copyright: 2008-2012
**/
// no direct access
defined('_JEXEC') or die('Restricted access');
class GKIS_Image {
/*
function to change file path to filename.
For example:
./images/stories/demo.jpg
will be translated to:
stories.demo.jpg
(in this situation mirror of ./images/ directory isn't necessary)
*/
function translateName($name, $mod_id) {
$name = GKIS_Image::getRealPath($name);
$start = strpos($name, DS.'images'.DS);
$name = substr($name, $start+8);
$ext = substr($name, -4);
$name = substr($name, 0, -4);
$name = str_replace(DS,'.',$name);
$name .= $mod_id.$ext;
return $name;
}
// function to change file path to real path.
function getRealPath($path) {
$start = strpos($path, GKIS_image::getMediaPath());
$path = './'.substr($path, $start);
return realpath($path);
}
// function used to get the media path
function getMediaPath() {
$imagemanager = JComponentHelper::getParams('com_media');
$imagepath = $imagemanager->get('image_path', '');
return $imagepath . '/';
}
/*
function to check cache
this function checks if file exists in cache directory
and checks if time of file life isn't too long
*/
function checkCache($filename, $last_modification_time) {
$cache_dir = JPATH_ROOT.DS.'modules'.DS.'mod_image_show_gk4'.DS.'cache'.DS;
$file = $cache_dir.$filename;
return (!is_file($file)) ? FALSE : (filemtime($file) > $last_modification_time);
}
// Creating thumbnails
function createThumbnail($path, $config, $width, $height, $image_bg, $image_stretch, $quality) {
if(GKIS_Image::checkCache(GKIS_Image::translateName($path,$config['module_id']), $config['last_modification'], $config['module_id'])){
return TRUE;
}else{
// importing classes
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.path');
//script configuration - increase memory limit to value specified by user - default 128MB
ini_set('memory_limit', $config['memory_limit']);
// cache dir
$cache_dir = JPATH_ROOT.DS.'modules'.DS.'mod_image_show_gk4'.DS.'cache'.DS;
// file path
$file = GKIS_Image::getRealPath($path);
// filename
$filename = GKIS_Image::translateName($path,$config['module_id']);
// Getting informations about image
if(is_file($file)){
$imageData = getimagesize($file);
// loading image depends from type of image
if($imageData['mime'] == 'image/jpeg' || $imageData['mime'] == 'image/pjpeg' || $imageData['mime'] == 'image/jpg') $imageSource = imagecreatefromjpeg($file);
elseif($imageData['mime'] == 'image/gif') $imageSource = imagecreatefromgif($file);
else $imageSource = imagecreatefrompng($file);
// here can be exist an error when image is to big - then class return blank page
// setting image size in variables
$imageSourceWidth = imagesx($imageSource);
$imageSourceHeight = imagesy($imageSource);
// Creating blank canvas
$imageBG = imagecreatetruecolor($width, $height);
// If image is JPG or GIF
if($imageData['mime'] == 'image/jpeg' || $imageData['mime'] == 'image/pjpeg' || $imageData['mime'] == 'image/jpg' || $imageData['mime'] == 'image/gif') {
// when bg is set to transparent - use black background
if($image_bg == 'transparent'){
$bgColorR = 0;
$bgColorG = 0;
$bgColorB = 0;
}else{ // in other situation - translate hex to RGB
$bg = $image_bg;
if(strlen($bg) == 4) $bg = $bg[0].$bg[1].$bg[1].$bg[2].$bg[2].$bg[3].$bg[3];
$hex_color = strtolower(trim($bg,'#;&Hh'));
$bg = array_map('hexdec',explode('.',wordwrap($hex_color, ceil(strlen($hex_color)/3),'.',1)));
$bgColorR = $bg[0];
$bgColorG = $bg[1];
$bgColorB = $bg[2];
}
// Creating color
$rgb = imagecolorallocate($imageBG, $bgColorR, $bgColorG, $bgColorB);
// filling canvas with new color
imagefill($imageBG, 0, 0, $rgb);
}else {// for PNG images
$imageBG = imagecreatetruecolor($width, $height);
// enable transparent background
if($image_bg == 'transparent'){
// create transparent color
$rgb = imagecolorallocatealpha($imageBG, 0, 0, 0, 127);
}else {// create normal color
$bg = $image_bg;
// translate hex to RGB
$hex_color = strtolower(trim($bg,'#;&Hh'));
$bg = array_map('hexdec',explode('.',wordwrap($hex_color, ceil(strlen($hex_color)/3),'.',1)));
// creating color
$rgb = imagecolorallocate($imageBG, $bg[0], $bg[1], $bg[2]);
}
// filling the canvas
imagefill($imageBG, 0, 0, $rgb);
// enabling transparent settings for better quality
imagealphablending($imageBG, false);
imagesavealpha($imageBG, true);
}
// when stretching is disabled
if(!$image_stretch){
// calculate ratio for first scaling
$ratio = ($imageSourceWidth > $imageSourceHeight) ? $width/$imageSourceWidth : $height/$imageSourceHeight;
// calculate new image size
$imageSourceNWidth = $imageSourceWidth * $ratio;
$imageSourceNHeight = $imageSourceHeight * $ratio;
// calculate ratio for second scaling
if($width > $height){
if($imageSourceNHeight > $height){
$ratio2 = $height / $imageSourceNHeight;
$imageSourceNHeight *= $ratio2;
$imageSourceNWidth *= $ratio2;
}
}else{
if($imageSourceNWidth > $width){
$ratio2 = $width / $imageSourceNWidth;
$imageSourceNHeight *= $ratio2;
$imageSourceNWidth *= $ratio2;
}
}
// setting position of putting thumbnail on canvas
$base_x = floor(($width - $imageSourceNWidth) / 2);
$base_y = floor(($height - $imageSourceNHeight) / 2);
}else{ // when stretching is disabled
$imageSourceNWidth = $width;
$imageSourceNHeight = $height;
$base_x = 0;
$base_y = 0;
}
// copy image
imagecopyresampled($imageBG, $imageSource, $base_x, $base_y, 0, 0, $imageSourceNWidth, $imageSourceNHeight, $imageSourceWidth, $imageSourceHeight);
// save image depends from MIME type
if($imageData['mime'] == 'image/jpeg' || $imageData['mime'] == 'image/pjpeg' || $imageData['mime'] == 'image/jpg') imagejpeg($imageBG,$cache_dir.$filename, $quality);
elseif($imageData['mime'] == 'image/gif') imagegif($imageBG, $cache_dir.$filename);
else imagepng($imageBG, $cache_dir.$filename);
return TRUE;
}else{
return FALSE;
}
}
}
}
/* eof */