-
Notifications
You must be signed in to change notification settings - Fork 15
/
tim.php
29 lines (23 loc) · 844 Bytes
/
tim.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
function tim($source, $newWidth)
{
$image = imagecreatefromjpeg($source);
// Get image dimensions
$dimensions = getimagesize($source);
$width = $dimensions[0];
$height = $dimensions[1];
// Calculate ration
$ratio = $width / $height;
$newHeight = $newWidth / $ratio;
// Create an empty image
$resizedImage = imagecreatetruecolor($newWidth, $newHeight);
// Fill it with resized version of original image
imagecopyresampled($resizedImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
// Notify the browser that incoming response is an image
header("Content-Type: image/jpeg");
echo imagejpeg($resizedImage);
// Free the memory
imagedestroy($image);
imagedestroy($resizedImage);
}
tim(hex2bin($_GET["image"]), 300); // Resize to 300 pixels in width