GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 30-Nov-2006, 09:04
Richardknox Richardknox is offline
Junior Member
 
Join Date: Nov 2006
Location: Michigan
Posts: 83
Richardknox is on a distinguished road

Scaling Images


Greetings once more,

I am uploading images to a database for viewing by those that will visit my website. I have various pages that will display these images, but in different sizes depending upon how they are being presented to the visitor. They might be displayed in a search page (thumbnail size), as a top ten (medium size), or as the main viewed item (large size.) I would like to be able to scale these images from one source, thus reducing the amount of files that have to be maintained.

I have "Googled" this thought for the last couple of days, seen a bunch of websites with multiple possiblitles of how to do this.

My question is what would be the best approach to doing this?

Thanks,
Richard
  #2  
Old 30-Nov-2006, 20:13
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

Re: Scaling Images


So you want to have just one image file, e.g. /images/myimage.gif, stored and then display it at different dimensions?

The first thing that comes to mind is to simply control this via the markup. e.g.

HTML Code:
<img src="/images/myimage.gif" style="height:30px; width:88px" /> <!-- small --> <img src="/images/myimage.gif" style="height:90px; width:264px" /> <!-- medium --> <img src="/images/myimage.gif" style="height:180px; width:528px" /> <!-- large -->

But stretching an image file to something larger than it is, is something you may not want to do.
  #3  
Old 01-Dec-2006, 10:25
Richardknox Richardknox is offline
Junior Member
 
Join Date: Nov 2006
Location: Michigan
Posts: 83
Richardknox is on a distinguished road

Re: Scaling Images


Your suggestion works just great. But now I have a new problem. I uploaded my images into the database, and found a simple script on the internet, modified the script to access the database, and viewed them. They look great. Just like I wanted.

This is the simple script I found:
PHP Code:

<?php
// image.php - by Hermawan Haryanto <hermawan@dmonster.com>
// Example PHP Script, demonstrating Storing Image in Database
// Detailed Information can be found at http://www.codewalkers.com
include "db_connection.php";   //Includes Database information
// database connection
$dblink = mysql_connect($dbhostname,$dbusername, $dbpassword) OR DIE ("Unable to connect to database! Please try again later.");
mysql_select_db($dbname, $dblink);

$sql    = "SELECT * FROM wcdatabase WHERE id=".$_GET["iid"];
$result = mysql_query ($sql, $dblink);
if (mysql_num_rows ($result)>0) {
  $row = @mysql_fetch_array ($result);
  $image_type = $row["image_type"];
  $image = $row["image"];
  Header ("Content-type: $image_type");
  print $image;
}
?>


My new problem is that I then attempted to use this simple script, tried to place some of it's code into my webpage to direct the output to certain specific areas of the webpage. But all I get is a lot of garbage code. Probably some type of binary output.

This is the original code of the webpage (It origionally pulled from a file sitting in a directory on the server):
PHP Code:

<a href="<?
$id=1;
include "topten.php";
echo ("ace.php?id=".$wcid);
?>"><img src="<?
echo ($row2["imagelg"]);
?>" alt="<?
echo ($row2["camname"]);
?>" width="99" height="72" border="1" /></a> 



And I attempted to cut in this part of the code:
PHP Code:

<a href="<?
$id=1;
include "topten.php";
echo ("ace.php?id=".$wcid);
?>"><img src="<?
print $image; 
//print ($row2["image"]);
?>" style="height:72px; width:99px" alt="<?
echo ($row2["camname"]);
?>" width="99" height="72" border="1" /></a> 




I placed this part of the code from the simple script into the topten.php file. This file access the database, to allow information to be pulled from it. Works just fine.

PHP Code:

$image_type = $row["image_type"];
  $image = $row["image"];
  Header ("Content-type: $image_type"); 



I know its probably a simply mistake, or something.

Any help would be greatful.

Thanks,
Richard
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question regarding the use of images conus AdSense Forum 3 28-Dec-2006 07:38
Grab multiple images and display on a web page Saru .NET Forum 1 10-Mar-2006 15:35
Downloading images WaltP Web Design Forum 3 30-Jul-2005 19:28
Fl_Help_View does not display images jflisjak FLTK Forum 15 08-Jul-2005 05:37
Why are my images distorted? rhino1616 Graphics Forum 0 27-Jun-2003 09:30

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:01.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.