iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 15, 2008
Reader Question - Would you host your client's work on your website?
About
 
May 15, 2008
How to Create an Ajax Autocomplete Text Field: Part 6
WebReference.com
 
May 14, 2008
Poll: Are the browser safe colors still needed?
About
 
May 14, 2008
Google Doctype launched
About
 
May 14, 2008
Web Editor Reviews - 6 New Reviews
About
 
May 14, 2008
Build Beautiful Buttons in Photoshop, Part I
SitePoint
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /PHP

Storage and re-use of images using PHP/GD - Part 1 

  Views:    26383
  Votes:    3
by Gijs van Tulder 4/30/04 Rating: 

Synopsis:

In this article, we will write some scripts that automates the uploading, storage, converting and resizing of our images.
Pages: firstback1 3 4 5 6 7 forwardlast
The Article

Creating the img tag

First, we need a function that, when provided with an image name, does this:

  • looks up the image information in the database
  • calculates the height and width of the image after resizing
  • builds the URL to the image retrieval script
  • combines these three parts in a nice img tag for use in our html.

The function

In imgtag.php, we start with defining the name of the table containing the image info and connecting to the database. Then, we open a function called img_tag, that will return the img tag.

// define database table containing image info
$img_table = "images";

// connect with database
mysql_connect("yourhost", "youruser", "password");
mysql_select_db("yourdb");

// generates and returns an img-tag
function img_tag($img_file, $attrib) {
    global $img_table;

To create an img tag, our function needs the following arguments passed:

  • $img_file: the 13-character filename of the image, as saved in the database and in the filesystem
  • $attrib: an array describing how we want the image to be. This associative array consists of the same one-letter keys we used in the resize script.

 

Pages: firstback1 3 4 5 6 7 forwardlast

Similar/related articles:


 
  Sponsors