Skip to content

Instantly share code, notes, and snippets.

@VishalTaj
Last active November 13, 2015 10:02
Show Gist options
  • Save VishalTaj/94c51825ce1bae1a5ed5 to your computer and use it in GitHub Desktop.
Save VishalTaj/94c51825ce1bae1a5ed5 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file"><br />
<input type="submit" value="Submit">
</form>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
$image = $_FILES["file"]["name"];
$uploadedfile = $_FILES["file"]["tmp_name"];
if($image){
$filename = stripcslashes($_FILES['file']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if($extension === "png"){
$src = imagecreatefrompng($uploadedfile);
list($width,$height) = getimagesize($uploadedfile);
$smallwidth=91;
$smallheight=80;
$thumbwidth=239;
$thumbheight=215;
$tmp=imagecreatetruecolor($smallwidth, $smallheight);
$thumbtmp=imagecreatetruecolor($thumbwidth, $thumbheight);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $smallwidth, $smallheight, $width, $height);
imagecopyresampled($thumbtmp, $src, 0, 0, 0, 0, $thumbwidth, $thumbheight, $width, $height);
$black = imagecolorallocate($tmp, 0, 0, 0);
imagecolortransparent($tmp, $black);
$filename='logo_small.png';
imagepng($tmp,$filename);
$black = imagecolorallocate($thumbtmp, 0, 0, 0);
imagecolortransparent($thumbtmp, $black);
$filename='logo_big.png';
imagepng($thumbtmp,$filename);
imagedestroy($src);
imagedestroy($tmp);
imagedestroy($thumbtmp);
}
else{
echo "File Type Not Supported <br /> Supported File Type:png";
}
}
else{
echo "No File Appended";
}
}
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
?>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment