| Server IP : 195.130.67.5 / Your IP : 216.73.216.231 Web Server : Microsoft-IIS/10.0 System : Windows NT WEBSERVER1 10.0 build 17763 (Windows Server 2016) i586 User : IUSR ( 0) PHP Version : 7.4.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/control/ |
Upload File : |
<?php
ini_set("memory_limit", "64M");
/*
$filenamepath = image to be resized
$newfilename = added to filename to for each use to keep from overwriting images created example thumbnail_$filename is how it will be saved.
$path = where the image should be stored and accessed.
$newwidth = resized width could be larger or smaller
$newheight = resized height could be larger or smaller
SAMPLE OF FUNCTION: makeimage('image.jpg','fullimage_','imgs/',250,250)
*/
//IMAGE RESIZE FUNCTION FOLLOW ABOVE DIRECTIONS
function makeimage($filenamepath,$newfilename,$path,$newwidth,$newheight) {
$patharr=explode("/",$filenamepath);
$num=count($patharr);
$filename=$patharr[$num-1];
//SEARCHES IMAGE NAME STRING TO SELECT EXTENSION (EVERYTHING AFTER . )
//$image_type = strstr($filename, '.');
$image_type = ".".pathinfo($filenamepath, PATHINFO_EXTENSION);
//SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION
switch(strtolower($image_type)) {
case '.jpg':
$source = imagecreatefromjpeg($filenamepath);
break;
case '.png':
$source = imagecreatefrompng($filenamepath);
break;
case '.gif':
$source = imagecreatefromgif($filenamepath);
break;
default:
echo("Error Invalid Image Type");
die;
break;
}
//CREATES THE NAME OF THE SAVED FILE
$file = $newfilename . $filename;
//CREATES THE PATH TO THE SAVED FILE
$fullpath = $path . $file;
//FINDS SIZE OF THE OLD FILE
list($width, $height) = getimagesize($filenamepath);
//CREATES IMAGE WITH NEW SIZES
$thumb = imagecreatetruecolor($newwidth, $newheight);
//RESIZES OLD IMAGE TO NEW SIZES
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
//SAVES IMAGE AND SETS QUALITY || NUMERICAL VALUE = QUALITY ON SCALE OF 1-100
imagejpeg($thumb, $fullpath, 80);
//CREATING FILENAME TO WRITE TO DATABSE
$filepath = $fullpath;
//RETURNS FULL FILEPATH OF IMAGE ENDS FUNCTION
return $filepath;
}
?>