PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hello
i am displaying images from a paticular folder,the code is working fine but i want to display all the image in same width and height...the code for displaying images is givn below
<?php
// define absolute path to image folder
$image_folder = 'IMAGE FOLDER NAME';
// get the image name from the query string
if (isset($_GET['pic']) && basename($_GET['pic']) == $_GET['pic'])
{
$pic = $image_folder.$_GET['pic'];
if (file_exists($pic) && is_readable($pic))
{
// get the filename extension
$ext = substr($pic, -3);
// set the MIME type
switch ($ext)
{
case 'jpg': $mime = 'image/jpeg';
break;
case 'gif': $mime = 'image/gif';
break;
case 'png': $mime = 'image/png';
break;
default: $mime = false;
}
// if a valid MIME type exists, display the image
// by sending appropriate headers and streaming the file
if ($mime)
{
header('Content-type: '.$mime);
header('Content-length: '.filesize($pic));
$file = @ fopen($pic, 'rb');
if ($file)
{
fpassthru($file); exit;
}
}
}
}
?>
This is often done using the GD Library because it can actually resize the image on the fly - but this should only be done if the size you want the image to be and the actual size are quite different. Simply using the height="" and width="" attributes in the img tag will distort the image if the aspect ratio is different on your desired, and actual sizes.
Granted not all servers have the GD Library, and it is slower than just setting attributes, but the resulting image will look much better and you can even store the resized image, and next time you look to pull it up, use the already resized image rather than resizing it again.
my problem is that i cant make a copy of all the image i receive from the user,it will take up lot of space which will be a wastage of space,and i am not using any image tag to show the image just i am calling the php files and the image is shown there.thats why i cant use the height and width property