Maybe its just me, but every time I load the page the error icons show instead of the actual image.
Please help me
<?php
if (isset($_GET['img'])){
if (file_exists($_GET['img'])){
ignore_user_abort(true);
set_time_limit(120);
ini_set('memory_limit', '512m');
$src_size = getimagesize($_GET['img']);
if ($src_size === false){
die ('That does not look like an image');
}
$thumb_width = 1100;
$thumb_height = 1100;
if ($src_size['mime'] === 'image/jpeg'){
$src = imagecreatefromjpeg($_GET['img']);
}else if ($src_size['mime'] === 'image/png'){
$src = imagecreatefrompng($_GET['img']);
}else if ($src_size['mime'] === 'image/gif'){
$src = imagecreatefromgif($_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){
//higher
$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){
//wider
$new_size = array (($thumb_width / $src_size[1]) * $src_size[0],$thumb_height);
$src_pos = array(($new_size[0] - $thumb_width) / 2, 0);
}else{
// same shape
$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']}");
}else if ($src_size['mime'] === 'image/png'){
imagepng($thumb, "thumbs/{$GET['img']}");
}else if ($src_size['mime'] === 'image/gif'){
imagegif($thumb, "thumbs/{$GET['img']}");
}
header("Location: thumbs/{$_GET['img']}");
}
die();
}
if (is_dir('./thumbs') === false){
mkdir('./thumbs', 0744);
}
$images = glob('*.{jpg,jpeg,png,gif}', GLOB_BRACE);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style stype="text/css">
a, img{float:left;}
</style>
<title>Image Gallery</title>
</head>
<body>
<div>
<?php
foreach($images as $image){
if (file_exists("./thumbs{$image}")){
echo "<a href=\"\"><img src=\"images/{$images}\" alt\"{$images}\" /></a>";
}else{
echo "<a href=\"\"><img src=\"?img/{$images}\" alt\"{$images}\" /></a>";
}
}
?>
</div>
</body>
</html>
I'll just send the codes I copy on tutorial...tags. I'm having trouble trying to figure out what your problem with this script is
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style stype="text/css">
a, img{float:left;}
</style>
<title>Image Gallery</title>
</head>
<body>
<div>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
<a href=""><img src="?img/Array" alt"Array" /></a>
</div>
</body>
</html>
foreach(glob("*.{jpg,JPG,jpeg,JPEG,png,PNG,gif,GIF}", GLOB_BRACE) as $file){
$image[] = basename($file);
}
And lower down in the file, around line 83 down, change those {$images} to {$image}.<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style stype="text/css">
a, img{float:left;}
</style>
<title>Image Gallery</title>
</head>
<body>
<div>
<a href=""> <img src="?img=5054193870_a648423b1e_o.jpg" alt"5054193870_a648423b1e_o.jpg" /></a><a href=""> <img src="?img=5106897146_98edafd5a1_o.jpg" alt"5106897146_98edafd5a1_o.jpg" /></a><a href=""> <img src="?img=5121878938_96735ba65f_o.jpg" alt"5121878938_96735ba65f_o.jpg" /></a><a href=""> <img src="?img=A little motivation 1024x768.jpg" alt"A little motivation 1024x768.jpg" /></a><a href=""> <img src="?img=ACE 1.jpg" alt"ACE 1.jpg" /></a><a href=""> <img src="?img=HOTTEST PAPERS ON THE NET (30).jpg" alt"HOTTEST PAPERS ON THE NET (30).jpg" /></a><a href=""> <img src="?img=Hydrangeas.jpg" alt"Hydrangeas.jpg" /></a><a href=""> <img src="?img=Jellyfish.jpg" alt"Jellyfish.jpg" /></a><a href=""> <img src="?img=Lighthouse.jpg" alt"Lighthouse.jpg" /></a><a href=""> <img src="?img=Untitled-2.jpg" alt"Untitled-2.jpg" /></a><a href=""> <img src="?img=anonymous-mask.jpg" alt"anonymous-mask.jpg" /></a><a href=""> <img src="?img=ep3ace.jpg" alt"ep3ace.jpg" /></a><a href=""> <img src="?img=fischfanger___think-t2.jpg" alt"fischfanger___think-t2.jpg" /></a><a href=""> <img src="?img=graffiti_technica_wallpaper_full.jpg" alt"graffiti_technica_wallpaper_full.jpg" /></a><a href=""> <img src="?img=hybridtech.jpg" alt"hybridtech.jpg" /></a><a href=""> <img src="?img=images.jpg" alt"images.jpg" /></a><a href=""> <img src="?img=micro.jpg" alt"micro.jpg" /></a><a href=""> <img src="?img=rainbow.jpg" alt"rainbow.jpg" /></a><a href=""> <img src="?img=tech.jpg" alt"tech.jpg" /></a><a href=""> <img src="?img=tech1.jpg" alt"tech1.jpg" /></a><a href=""> <img src="?img=tech3.jpg" alt"tech3.jpg" /></a><a href=""> <img src="?img=redline_f.JPG" alt"redline_f.JPG" /></a>
</div>
</body>
</html>
<?php
foreach($images as $image){
if (file_exists("./thumbs{$image}")){
echo "<a href=\"\"><img src=\"images/{$images}\" alt\"{$images}\" /></a>";
}else{
echo "<a href=\"\"><img src=\"?img/{$images}\" alt\"{$images}\" /></a>";
}
}
?>
$images is an array. You need to use $image when you echo. <?php
foreach($images as $image){
if (file_exists("./thumbs{$image}")){
echo "<a href=\"\"><img src=\"images/{$image}\" alt\"{$image}\" /></a>";
}else{
echo "<a href=\"\"><img src=\"?img/{$image}\" alt\"{$image}\" /></a>";
}
}
?>
I am also fairly sure that you need a slash between thumbs and {$image} here:
if (file_exists("./thumbs{$image}")){
don't quote me on that though. Try it for yourself.If you look at the image location "?img=5054193870_a648423b1e_o.jpg" it looks right, so if you paste that into your browser to actually view the thumbnail it might tell you why it's not generating one.ijohnrussel wrote:i follow all what you have told me but i have still the same problem.. same with the first image post i did...