How To Display Pictures Or Image With Php File Script Showing How To Link Photo With Php File

Mobile
feeds
Welcome Login | Register

How To Display Pictures Or Image With Php File Script Showing How To Link Photo With Php File
  Forums Index
      » PHP Forums
        » » how to display pictures or image with php file script showing how to link photo with php file



How To Display Pictures Or Image With Php File Script Showing How To Link Photo With Php File
Post Description:
Post Tags: how, to, display, pictures, or, image, with, php, file, script, showing, how, to, link, photo, with, php, file, free php support, php scripts, php questions, php answers, programming, codes, scripts
This Post Has Been Viewed 520 Times Since Mon May 14, 2007 4:09 am Posted By hostman with 1 replies
How To Display Pictures Or Image With Php File Script Showing How To Link Photo With Php File
have you ever seen a picture or an image being on a website, and when you see the properties its a php file. with php, you can do these cool tricks.

to do this, just copy and paste this code and save the file as image.php
<?
$img="example.gif";
header ('content-type: image/gif');
readfile($img);
?>


so now lets say you have a webpage and you want the example.gif image to be displayed using this php file, you can.

instead of using this for example:
<img src="example.gif">
you can use this instead
<img src="example.php" >




Leave Your Comments






Share
URL:
You can use this HTML code to put it on your website to show your friends this wallpaper. Use this code on your profile like myspace, friendster, Facebook or others. Just Copy and Paste it in your HTML on your websites



Fourms BBCODE:
BBCODE is use on forums. You can put this code on all your BBCODE enabled forums like PhpBB, vBulletin® and others. Just Copy and Paste this code on your Posts and Replies on your forums





Comments and replies About How To Display Pictures Or Image With Php File Script Showing How To Link Photo With Php File




:: 1 :: Reply #3153 Reply By lakig On Mon May 14, 2007 4:13 am
i've seen this before
Here you will learn how to display image and how to create image thumbnail with PHP. To use PHP image functions you have to uncomment extension line in PHP.INI file. Find PHP.INI file in "C:\PHP" directory and in "C:\WINNT\System32\" directory. Scroll down to Windows Extensions and delete ";" character in front of gd2.dll

PHP.INI

;Windows Extensions
;Note that MySQL and ODBC support is now built in, so no dll is needed for it.
; ;extension=php_mbstring.dll
;extension=php_bz2.dll
;extension=php_cpdf.dll
;extension=php_crack.dll
;extension=php_curl.dll
;extension=php_db.dll
;extension=php_dba.dll
;extension=php_dbase.dll
;extension=php_dbx.dll
;extension=php_domxml.dll
;extension=php_exif.dll
;extension=php_fdf.dll
;extension=php_filepro.dll
extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_hyperwave.dll

Open notepad or textpad and write a PHP code:

<?php

$imagepath="phpimages/dog.jpg";

$image=imagecreatefromjpeg($imagepath);

header('Content-Type: image/jpeg');

imagejpeg($image);

?>


Save the file as image.php in "htdocs/dspimage" directory. Create "phpimages" directory inside dspimage directory and place inside an image. In my example image file name is "dog.jpg". If your image file name is different, then change the image file name in php code. Image file must have jpg extension. Of course, it is possible to display gif or png images, but for now use jpg image for simplicity sake.

Start Apache and your browser and type in the URL: http://localhost/dspimage/image.php.

Image will be displayed. It is easy to understand the code.

1. You get path to the image file

2. You create image using function imagecreatefromjpeg (for jpg image file) If you has gif image then you have to use imagecreatefromgif function.

3. You have to set mime type in header so that your browser knew what kind of data will sent to it.

4. You display image in browser with imagejpeg function.

Actually, imagejpeg function has two more arguments. It can output image in file for example:

imagejpeg($image, "newfile.jpg", 50);

The third argument is image quality. If you enter a file name then jpg file will be created, but browser will not display the image.

You can display caption on the image. Add few lines of code. Get image height, allocate color, display caption text with font 5 and color white, 100 pixels from the left and 50 from the bottom.
<?php

$imagepath="phpimages/dog.jpg";

$image=imagecreatefromjpeg($imagepath);

// get image height

$imgheight=imagesy($image);

//allocate color for image caption (white)

$color=imagecolorallocate($image, 255, 255, 255);

//Add text to image bottom

imagestring($image, 5, 100, $imgheight-50, "September 2005", $color);

header('Content-Type: image/jpeg');

imagejpeg($image);

?>


Problem with this code is that you cannot display any text on the page, because you set mime type for image/jpeg. If you want to display the image on the page with text use image.php file as source for the img src tag