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 16, 2008
Who Are Your Top Friends on Facebook?
About
 
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
 
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:    26391
  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 2 3 4 5 7 forwardlast
The Article

Execute and count the results:

// execute the query
$result = mysql_query($query);

// get the number of results
$num_rows = mysql_num_rows($result);

The results

We start with a basic html-page. We also include a JavaScript function (borrowed from www.vpro.nl) to display the popup with a larger version of the image.

?><html>
<script language="javascript">
/* source:
www.vpro.nl */
function bigImage(name) {
 if (navigator.appName=="Netscape") {
  var imagewindow = window.open('bigimage.php?f='+name,'imagewindow'+name,

'resizable=yes,scrollbars=no,status=1,innerWidth=450,innerHeight=402');
 }
 else {
  var imagewindow = window.open('bigimage.php?f='+name,'imagewindow'+name,

 'resizable=yes,scrollbars=yes,status=1,width=450,height=402');
 }
}
</script>
<body>
<h1>Search Results</h1>
<table><?php

Per image, we display one table row. We add a popup link to bigimage.php, a script that displays a larger version of the image. We just link to it for now, we will write bigimage.php in the next step. The img_tag function is used to generate the img tag.

// one row for each result
for ($i=0; $i<$num_rows; $i++) {
    // fetch row
    $img_info = mysql_fetch_array($result);

    // start table row
    echo '<tr><td><a href="bigimage.php?f='.$img_info["img_file"].'" '.
         'target="_new" onclick="bigImage('."'".$img_info["img_file"]."')".
         '; return false;">';

    // generate the image tag
    echo img_tag($img_info["img_file"], array("x"=>"250"));

    // echo image information
    echo "</a></td><td><b>".$img_info["img_title"]."</b><br>".
         $img_info["img_descr"]."<hr><b>Alt:</b> ".$img_info["img_alt"].
         "<br><b>Pixels:</b> ".$img_info["img_width"]."x".
         $img_info["img_height"]."<br><b>Bytes:</b> ".
         $img_info["img_bytes"]."<br><b>Type:</b> ".
         $img_info["img_type"]."</td></tr>\n";
}

Now just close the table, body and html tags and your search script is finished.


Bigimage.php

As said, this script isn't very complicated. It uses the img_tag function to display a larger version of the image. That image links to the full-size version of the image. Save the code as bigimage.php and you're ready.

<html>
<body>
<?php
include("imgtag.php");

echo '<a href="img.php?f('.$HTTP_GET_VARS["f"].')">';
echo img_tag($HTTP_GET_VARS["f"], array("x"=>"400"));
echo '</a>';
?>
</body>
</html>

Pages: firstback1 2 3 4 5 7 forwardlast

Similar/related articles:


 
  Sponsors