Dynamic Image With PHP
Normally if we want to use image on HTML we must using IMG tag with direct link of any image. But now with PHP we can do a little tricks. Just for fun and maybe it’s usefull for you. Who knows
Let’s get started.
This is normally IMG tag.
<img src=”http://domain.com/your-image-url.gif” />
But now we change like this.
<img src=”http://domain.com/img.php?img=3″ />
That’s just an example. So here is the code
<?php
/*
By using this script you agree not to remove the link of coded by Ferri
Homepage : http://smileylover.com
Friendster Smiley, MySpace Smiley, Forum Smiley.
*/error_reporting(E_ALL);
if(isset($_GET['img'])) {
$img = $_GET['img'];
if(get_magic_quotes_gpc())
{
$img = stripslashes($img);
}$image = array
(’1′ => ‘URL-IMAGE-1′,
’2′ => ‘URL-IMAGE-2′,);header( “Content-type: image/gif” );
@readfile (“$image[$img]“);}
?>
Save code above into img.php then set your image url into array. Example you set in array 1 -> http://img368.imageshack.us/img368/9987/11lq3.gif and to call it with php set this code to get the same image.
http://domain.com/img.php?img=1
It can hide the real image url or hide long url. So enjoy it
Hi guys,
i have analyzed the image uploading here. Also it creates dynamic thumbnail images also. Please have a check.
Image Details
Plese Fill Up The Form
Enter Your Name:
Upload Your Photo:
<?
function resize_image($src_file,$dst_file,$dst_w,$dst_h,$src_w,$src_h)
{
$source_image = imagecreatefromjpeg($src_file);
$thumb_image = imagecreatetruecolor($dst_w,$dst_h);
imagecopyresampled($thumb_image,$source_image,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h);
imagejpeg($thumb_image,$dst_file,100);
}
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$type = $_FILES['img']['type'];
$percentage = 0.5;
echo “File Type: “.$type.”";
if($type == ‘image/jpeg’ || $type == ‘image/gif’)
{
$fname = $_FILES['img']['name']; //Gets the name of the image.
$fsize = $_FILES['img']['size']; //Gets the size of the image.
$ftemp = $_FILES['img']['tmp_name']; //Gets the temporary name of the image.
$ftype = $_FILES['img']['type']; //Gets the type of image.
list($width,$height,$type,$attr) = getimagesize($_FILES['img']['tmp_name']);
$new_width = $width * $percentage;
$new_height = $height * $percentage;
//Now it gets the extension of the image.
$ext = substr($fname,strpos($fname,’.'));
$fsize_kb = $_FILES['img']['size'].” bytes”;
if($fsize_kb >= 1024)
{
$fsize_kb = number_format(($fsize_kb/1024),’2′);
}
$path1 = “image_details/”.$name; //”image_details” is the name of the folder. Under “image_details”, it’s creating a new folder with the given name.
if(is_dir($path1))//Checks whether the path exists or not
{
$files = scandir($path1);
$files = array_diff($files, array(‘.’, ‘..’));
$count = count($files);
if($count <= 0)
{
$count++;
$large_path = $path1.”/”.$name.”_large_”.$count.”.jpg”;
$thumb_path = $path1.”/”.$name.”_thumb_”.$count.”.jpg”;
$new_name = $name.”_large_”.$count.”.jpg”; // Modified name of the image.
$new_name_thumb = $name.”_large_”.$count.”.jpg”; // Modified thumb name of the image.
$upload = move_uploaded_file($_FILES['img']['tmp_name'], $large_path);
chmod($large_path, 0666);
resize_image($large_path,$thumb_path,$new_width,$new_height,$width,$height);
chmod($thumb_path,0666);
}
else
{
$count++;
$large_path = $path1.”/”.$name.”_large_”.$count.”.jpg”;
$thumb_path = $path1.”/”.$name.”_thumb_”.$count.”.jpg”;
$new_name = $name.”_large_”.$count.”.jpg”; // Modified name of the image.
$new_name_thumb = $name.”_large_”.$count.”.jpg”; // Modified thumb name of the image.
$upload = move_uploaded_file($_FILES['img']['tmp_name'], $large_path);
chmod($large_path, 0666);
resize_image($large_path,$thumb_path,$new_width,$new_height,$width,$height);
chmod($thumb_path,0666);
}
}
else//If the path doesn’t exist
{
mkdir($path1);//creates a new folder
chmod($path1, 0777);
$large_path = $path1.”/”.$name.”_large_1.jpg”;
$thumb_path = $path1.”/”.$name.”_thumb_1.jpg”;
$new_name = $name.”_large_1.jpg”; // Modified name of the image.
$new_name_thumb = $name.”_thumb_1.jpg”; // Modified thumb name of the image.
$upload = move_uploaded_file($_FILES['img']['tmp_name'], $large_path);
chmod($large_path, 0666);
resize_image($large_path,$thumb_path,$new_width,$new_height,$width,$height);
chmod($thumb_path,0666);
}
if($upload)
{
echo “Successfully Uploaded.“;
}
else
{
echo “Problem In uploading.“;
}
?>
Details
Original Filename:
Modified Filename:
Modified Thumb name:
Filesize in bytes:
Temp Name:
File Type:
Image Height:
px
Image Width:
px
Image Type:
Image Attribute:
Thumbnail Width:
Thumbnail Height:
Filesize in KB:
Extention of Image:
<?
}
else
{
echo “It should be in JPEG or GIF format.“;
}
}
?>
Nice
ops… my article not about image uploader . but hide real path of image, and give unique links :
reagrds
Nice Coding…. great…. keep it up …… very useful coding…. tusi great ho…. my problem solved… thanks