AnonSec Team
Server IP : 103.11.96.170  /  Your IP : 18.223.97.137
Web Server : Microsoft-IIS/10.0
System : Windows NT WIN-F6SLGVICLOP 10.0 build 17763 (Windows Server 2016) AMD64
User : elibrary.unsap.ac.id ( 0)
PHP Version : 7.4.19
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF
Directory (0777) :  D:/localhost/elibrary/lib/minigalnano/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : D:/localhost/elibrary/lib/minigalnano/createthumb.php
<?php
/*
Heavily modified for SLiMS by Hendro Wicaksono (hendrowicaksono@yahoo.com)
(Senayan Library Management System), http://slims.web.id / http://senayan.diknas.go.id
It is derived from:
---------------------
MINIGAL NANO
- A PHP/HTML/CSS based image gallery script
This script and included files are subject to licensing from Creative Commons (http://creativecommons.org/licenses/by-sa/2.5/)
You may use, edit and redistribute this script, as long as you pay tribute to the original author by NOT removing the linkback to www.minigal.dk ("Powered by MiniGal Nano x.x.x")
MiniGal Nano is created by Thomas Rybak
Copyright 2010 by Thomas Rybak
Support: www.minigal.dk
Community: www.minigal.dk/forum
Please enjoy this free script!
USAGE EXAMPLE:
File: createthumb.php
Example: <img src="createthumb.php?filename=photo.jpg&amp;width=100&amp;height=100">
----------------------
Updated Example: $size is not used. Only width and height.
*/
//	error_reporting(E_ALL);

// Define variables
$target = "";
$xoord = 0;
$yoord = 0;
$default_res_width = 42;
$cache['enable'] = false;
$cache['folder'] = '../../images/cache/'; # try absolutely in case of error about safe mode in PHP
$cache['exist'] = false;
$cache['handle'] = '';
$imagefilename = urldecode(trim($_GET['filename']));

function genContentType($imagefilename)
{
  if (preg_match("/.jpg$|.jpeg$/i", $imagefilename)) header('Content-type: image/jpeg');
  if (preg_match("/.gif$/i", $imagefilename)) header('Content-type: image/gif');
  if (preg_match("/.png$/i", $imagefilename)) header('Content-type: image/png');
}

# Only accept JPG, PNG, GIF
if (!((preg_match("/.jpg$|.jpeg$/i", $imagefilename)) OR (preg_match("/.gif$/i", $imagefilename)) OR (preg_match("/.png$/i", $imagefilename)))) {
  header('Content-type: image/png');
  readfile('wrongcontenttype.png');
  exit;
}

// Display error image if file isn't found
if (!is_file($imagefilename)) {
  header('Content-type: image/png');
  readfile('filenotfound.png');
  exit;
}

// Display error image if file exists, but can't be opened
if (!is_readable($imagefilename)) {
  header('Content-type: image/png');
  readfile('filecantbeopened.png');
  exit;
}

$imgsize = GetImageSize($imagefilename);
$width = $imgsize[0];
$height = $imgsize[1];

if ((isset($_GET['width'])) AND (trim($_GET['width']) != '')) {
  $res_width = $_GET['width'];
} else {
  $res_width = $default_res_width;
}

if ((isset($_GET['height'])) AND (trim($_GET['height']) != '')) {
  $res_height = $_GET['height'];
} else {
  $res_height = ($res_width/$width) * $height;
}

$cache['prefix'] = '_slims_img_cache_'.$res_width.'_x_'.$res_height.'_';
$cache['file'] = $cache['folder'].$cache['prefix'].basename($imagefilename);

if (file_exists($cache['file'])) {
  $cache['exist'] = true;
  genContentType($imagefilename);
  readfile($cache['file']);
  exit;
} else {
  $cache['exist'] = false;
}

genContentType($imagefilename);

$target = imagecreatetruecolor($res_width,$res_height);
if (preg_match("/.jpg$|.jpeg$/i", $imagefilename)) $source = imagecreatefromjpeg($imagefilename);
if (preg_match("/.gif$/i", $imagefilename)) $source = imagecreatefromgif($imagefilename);
if (preg_match("/.png$/i", $imagefilename)) $source = imagecreatefrompng($imagefilename);

// preserve transparency
imagealphablending($target, false);
imagesavealpha($target,true);
$transparent = imagecolorallocatealpha($target, 255, 255, 255, 127);
imagefilledrectangle($target, 0, 0, $res_width, $res_height, $transparent);

imagecopyresampled($target,$source,0,0,$xoord,$yoord,$res_width,$res_height,$width,$height);
imagedestroy($source);

if ($cache['exist'] == false) {
  if (preg_match("/.jpg$|.jpeg$/i", $imagefilename)) {
    imagejpeg($target,null,90);
    imagejpeg($target,$cache['file'],90);
  }
  if (preg_match("/.gif$/i", $imagefilename)) {
    imagegif($target,null);
    imagegif($target,$cache['file']);
  }
  if (preg_match("/.png$/i", $imagefilename)) {
    imagepng($target,null,9);
    imagepng($target,$cache['file'],9);
  }
  imagedestroy($target);
}         
exit;

AnonSec - 2021