Forum Moderators: coopster
The idea is to call:
<img src="http://foo.com/img.php?tipo=album&img=my_pic2.jpg" /> My problem is when i call:
[foo.com...]
It prints a blank page. Since im putting the URL in the src attribute of the <img> tag, should I send a special header when theres no image?
Here's the code of img.php
**************************
if(!$_GET['img'] ¦¦!$_GET['tipo']) die();
$file = DIR_UPLOAD.basename($_GET['tipo']).'/'.basename($_GET['img']);
if(file_exists($file)) {
$img = new img($file);
$img->resize($_GET['s'],$_GET['c']);
$img->show();
}
class img {
var $imagen;
var $temp;
var $ext;
function img($file) {
$info = pathinfo($file);
$this->ext = $info['extension'];
switch($this->ext) {
# GIF
case 'gif':
$this->imagen = ImageCreateFromGIF($file);
break;
# JPEG
case 'jpe': case 'jpeg': case 'jpg':
$this->imagen = ImageCreateFromJPEG($file);
break;
# PNG
case 'png':
$this->imagen = ImageCreateFromPNG($file);
break;
# ...
default: return;
}
}
function resize($size=false,$cuadrado=false) {
if(!$size) $size = 100;
$width_original = imagesx($this->imagen);
$height_original = imagesy($this->imagen);
if($cuadrado) {
$width = $height = $size;
} else {
$width = $size;
$height = round($height_original * $width / $width_original);
}
$this->temp = imageCreateTrueColor($width,$height);
imageCopyResampled($this->temp,$this->imagen,0,0,0,0,$width,$height,$width_original,$height_original);
$this->imagen =& $this->temp;
unset($this->temp);
return;
}
function show() {
header('Content-Type: image/jpeg');
switch($this->ext) {
# GIF
case 'gif':
ImageGIF($this->imagen);
break;
# JPEG
case 'jpe': case 'jpeg': case 'jpg':
ImageJPEG($this->imagen);
break;
# PNG
case 'png':
ImagePNG($this->imagen);
break;
# ...
default: return;
}
}
}
******************
Any ideas welcomed.
To:
if(empty($_GET["img"] ¦¦ empty($_GET{"tipo"]))
{
die("Url query not correct.");
exit;
}
if(empty($_GET["img"] ¦¦ empty($_GET["tipo"]))
{
die("Url query not correct.");
exit;
}
Sorry about that ;)
Is this what you are trying to accomplish?
Thats why i have to generate a black square with the "?" in the middle. How can i accomplish that?