I have this function I call for creating thumbnails
Code: Select all
<?php
chdir("uploads");
function create_thumbs(){
if (isset($_GET['img'])) {
$src_size = getimagesize($_GET['img']);
if($src_size === false){
die("This is not an image");
}
$thumb_width = 120;
$thumb_height = 140;
if ($src_size['mime'] === 'image/jpeg') {
$src=imagecreatefromjpeg($_GET['img']);
}
$src_aspect = round(($src_size[0] / $src_size[1]), 1);
$thumb_aspect = round(($thumb_width / $thumb_height), 1);
if($src_aspect < $thumb_aspect) {
$new_size = array($thumb_width,($thumb_width / $src_size[0])* $src_size[1]);
$src_pos =array(0,($new_size[1] - $thumb_height) /2);
}else if($src_aspect > $thumb_aspect){
$new_size= array(($thumb_width / $src_size[1])* $src_size[0], $thumb_height);
$src_pos =array(($new_size[0] - $thumb_width) /2, 0);
}else{
$new_size =array($thumb_width, $thumb_height);
$src_pos= array(0, 0);
}
if ($new_size[0] < 1) $new_size[0] = 1;
if ($new_size[1] < 1) $new_size[1] = 1;
$thumb =imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($thumb, $src, 0,0, $src_pos[0],$src_pos[1], $new_size[0],$new_size[1], $src_size[0], $src_size[1]);
if ($src_size['mime'] === 'image/jpeg') {
(imagejpeg($thumb, "thumbs/{$_GET['img']}"));
}
header("Location: thumbs/{$_GET['img']}");
}
}
$images = glob('*.{jpg,jpeg,gif,png}',GLOB_BRACE);
?>
<html>
<style>
a,img{float:left;}
</style>
<div>
<?php
foreach($images as $image) {
if(file_exists("./thumbs/{$image}")) {
echo"<a href=\"{$image}\"><img scr=\"thumbs/{$image}\" alt=\"{$image}\" /></a>";
}else{
echo "<a href=\"{$image}\"><img src=\"?img={$image}\" alt=\"{$image}\" /></a>";
}
}
?>
It creates the thumbs puts them in the thumbs dir, but does not display them. It looks like it fails on this line
Code: Select all
if(file_exists("./thumbs/{$image}")) {
Code: Select all
$images = glob('*.{jpg,jpeg,gif,png}',GLOB_BRACE);
?>
<html>
<style>
a,img{float:left;}
</style>
<div>
<?php
foreach($images as $image) {
if(file_exists("./thumbs/{$image}")) {
echo"<a href=\"{$image}\"><img scr=\"thumbs/{$image}\" alt=\"{$image}\" /></a>";
}else{
echo "<a href=\"{$image}\"><img src=\"?img={$image}\" alt=\"{$image}\" /></a>";
}
}
Can anyone see what I am doing wrong or what I have missed.
Thank you in advance for your help