Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Modifying the Script - Page 16

January 12, 2001

We then have to modify our showmall.php script to handle thumbnails:

<?php
//showmall2.php
include "./common_db.inc";
Header("Content-type: image/png");
if ($show!="") {
  $image = ImageCreateFromPNG("groundfloor.png");
  $shops = explode(",", urldecode($show));
  $link_id = db_connect('mapping');
  $gray = ImageColorAllocate($image,204,204,204);
  for ($x=0;$x<count($shops);$x++) {
    $query = "SELECT m_area,m_center FROM mall
	  WHERE m_id=".$shops[$x];
    $mallResult = mysql_query($query,$link_id);
    $mallRow = mysql_fetch_array($mallResult);
    $center = explode(",",$mallRow[1]);
    ImageFill($image,$center[0],$center[1],$gray);
  }
} else {
  $image = ImageCreate(100,50);
  $white = ImageColorAllocate($image,255,255,255);
  $black = ImageColorAllocate($image,0,0,0);
  ImageString($image,5,1,1,"Error",$black);
}
if ($thumbnail=="on") {
  $thumb = ImageCreate(100,100);
  ImageCopyResized($thumb,$image,0,0,0,0,100,100,500,500);
  ImagePNG($thumb);
} else {
  ImagePNG($image);
}
ImageDestroy($image);
?>
[Lines 11 and 12 above are one line. They have been split for formatting purposes.]

When we run our script we should see this sort of result:

image24.jpg

How It Works

Malldetail.php writes out an HTML file that contains the information about the shop, as well as a thumbnail image of the mall layout. This is the line that creates the image:

<IMG SRC="showmall.php?show=<?php echo $mallRow[0]; ?>&thumbnail=on"
WIDTH=100 HEIGHT=100>
This is almost exactly as we've seen before; the only difference is that the script has the extra argument of thumbnail=on. In showmall.php we now check whether to output a thumbnail or the full size image. All we need to change is the line:
ImagePNG($image);
We check for the value of $thumbnail, and if it's 'on' we resize the mall plan from its original dimensions of 500x500 to a more compact 100x100:
if ($thumbnail=="on") {
  $thumb = ImageCreate(100,100);
  ImageCopyResized($thumb,$image,0,0,0,0,100,100,500,500);
  ImagePNG($thumb);
} else {
  ImagePNG($image);
}
If the $thumbnail variable isn't set (or is set to anything other than "on") we display the image as normal.

Showing the Shop Detail - Page 15
Beginning PHP4
Advanced Graphics Manipulation - Page 17


Up to => Home / Authoring / Languages / PHP / BeginningPHP4




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers