forked from fenimore/wink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_thumbnail.php
executable file
·71 lines (66 loc) · 2.66 KB
/
make_thumbnail.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
session_start();
if(!isset($_SESSION['loggedin'])){
header("Location:login.php");
return;
}
// https://davidwalsh.name/create-image-thumbnail-php
function make_thumb($src, $dest, $desired_width) {
/* read the source image */
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
/* find the "desired height" of this thumbnail, relative to the desired width */
$desired_height = floor($height * ($desired_width / $width));
/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
/* copy source image at a resized size */
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
/* create the physical thumbnail image to its destination */
imagejpeg($virtual_image, $dest);
}
echo '<h1>Making thumbnails for selected category</h1>';
$category = $_REQUEST['category'];
$overwrite = $_REQUEST['over'];
$galleries = glob('media/'.$category.'/*');
$status = '';
foreach($galleries as $gallery) {
$path = 'media/'. $category . '/' . basename($gallery) . '/';
$images = glob($path."*.{[jJ][pP][gG],gif,jpeg,svg,bmp,png}", GLOB_BRACE);
$thumbpath = $path . 'thumbnails/';
if (file_exists($thumbpath) && $overwrite != 'true'){
$status = $status . '<h2>gallery: '.basename($gallery).' Already Exists</h2>';
continue;
}
mkdir($thumbpath, 0755, true);
$status = $status . '<h2>gallery: '.basename($gallery).'</h2>';
foreach($images as $image) {
$info = pathinfo($image);
$thumb = $thumbpath.'thmb-' . $info['filename'] . '.' . $info['extension'];
make_thumb($image, $thumb, 150);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Wink</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Photo Gallery">
<meta name="keywords" content="PHP, Photography">
<meta name="author" content="Fenimore">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- jQuery library -->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen"/>
</head>
<body>
<?php echo $status; ?>
<a href="auth/admin.php">Return to Admin</a><br>
<a href="index.php">Return to Index</a>
</body>
</html>