Jump to content

image size


techker

Recommended Posts

hey guys my script calls a picture in my database.they only thing is i need to resize it but it does not seem to work?

 

pics.php?pid=3

 

// Connect to database 

$errmsg = "";
if (! @mysql_connect("localhost","here","there")) {
$errmsg = "Cannot connect to database";
}
@mysql_select_db("techker_here");
// Find out about images to display 
$pid = mysql_escape_string($_GET['pid']);
if ($_GET['pid']) { 
   $whereclause = "where pid = \"$pid". 
      $_GET['pid']. 
      "$pid\""; 
   $gotten = @mysql_query("select * from pix  order by pid desc "); 
   while ($row = @mysql_fetch_assoc($gotten)) { 
      $imcolumn .= "<tr><td><img src=?pid=$row[pid] width=144 ><br>"; 
      $imcolumn .= htmlspecialchars($row[title])."</td></tr>"; 
      $nim++; 
   } 
   if (! $nim) $imcolumn = "<tr><td>No matching images</td></tr>"; 
} else { 
   $imcolumn .= "<tr><td>Images will appear here</td></tr>"; 
} 

// If this is the image request, send out the image 

if ($_GET['pid']) { 
   $gotten = @mysql_query("select * from pix where pid = $_GET[pid]"); 
   $row = mysql_fetch_assoc($gotten); 
   $bytes = $row[imgdata]; 
   header("Content-type: image/jpeg"); 
   print $bytes; 
   exit (); 
   } 

?> 

<html><head> 
<title>Selection of up to 3 images from a database</title> 
<body bgcolor=white><h2> </h2> 
<font color=red><?= $errmsg ?></font> 
<center><table border=1> 
<b><?= $imcolumn ?></table></center> 
<hr> 
</body> 
</html> 

 

Link to comment
Share on other sites

You need to make a better effort here if you want help.  Be more specific than "It doesn't work."

 

Remove your error suppressions and add some error messaging to your stuff. Example, change this:

 

$gotten = @mysql_query("select * from pix  order by pid desc "); 

 

to this (on all of your mysql_.xxx functions)

 

$gotten = mysql_query("select * from pix  order by pid desc ") or die(mysql_error());; 

 

Any error messages?

 

Echo all your vars out, do they contain what you expect?

 

Link to comment
Share on other sites

function scale_image($p,$mw='',$mh='') { // path max_width max_height
    if(list($w,$h) = @getimagesize($p)) {
    foreach(array('w','h') as $v) { $m = "m{$v}";
        if(${$v} > ${$m} && ${$m}) { $o = ($v == 'w') ? 'h' : 'w';
        $r = ${$m} / ${$v}; ${$v} = ${$m}; ${$o} = ceil(${$o} * $r); } }
    return("<img src='{$p}' alt='image' width='{$w}' height='{$h}' alt='Click to view this members profile' style='margin-top:3px;' />"); }
}

 

then where you what the picture use

 

echo scale_image('imageURL',w,h); // change w to the max width and h to the max height in px ie scale_image('image.png',100,120) it scales the image to 

 

i havn't looked into using in your code but it might help

Link to comment
Share on other sites

Check your page source once the code is run. Somewhere you should see the img tag if its all worked properly.

 

<img src="you.image" width=144  >

 

I'm guessing you want a standard width, so that the height can change. If you see the width=144 and it still doesn't work try complying to XHTML standards;

 

<img src="you.image" width="144"  />

Link to comment
Share on other sites

Check your page source once the code is run. Somewhere you should see the img tag if its all worked properly.

 

<img src="you.image" width=144  >

 

I'm guessing you want a standard width, so that the height can change. If you see the width=144 and it still doesn't work try complying to XHTML standards;

 

 

 

<img src="you.image" width="144"  />

 

the image is ain a variable

 

$imcolumn .= "<tr><td><img src=?pid=$row[pid] width=144 ><br>";

 

<b><?= $imcolumn ?></table></center>

 

it is that im using? but i will try with the ""

Link to comment
Share on other sites

function scale_image($p,$mw='',$mh='') { // path max_width max_height
    if(list($w,$h) = @getimagesize($p)) {
    foreach(array('w','h') as $v) { $m = "m{$v}";
        if(${$v} > ${$m} && ${$m}) { $o = ($v == 'w') ? 'h' : 'w';
        $r = ${$m} / ${$v}; ${$v} = ${$m}; ${$o} = ceil(${$o} * $r); } }
    return("<img src='{$p}' alt='image' width='{$w}' height='{$h}' alt='Click to view this members profile' style='margin-top:3px;' />"); }
}

 

then where you what the picture use

 

echo scale_image('imageURL',w,h); // change w to the max width and h to the max height in px ie scale_image('image.png',100,120) it scales the image to 

 

i havn't looked into using in your code but it might help

 

this is not working for me..thx

Link to comment
Share on other sites

strange i copied that from a page i have it working fine on.

 

to add to what gavin said "" will probaly just out the 144 and not use the rest of the string, try width='144' in stead

or even width=".144." might do the job or have you thought of giving the images an id then use css to resize.

Link to comment
Share on other sites

strange i copied that from a page i have it working fine on.

 

to add to what gavin said "" will probaly just out the 144 and not use the rest of the string, try width='144' in stead

or even width=".144." might do the job or have you thought of giving the images an id then use css to resize.

 

maybe it does work but i can't seem to figure it out in my script..

 

if it try ".144." it gives me an error and the other nothing?

Link to comment
Share on other sites

What do you mean you cant view the source?  Every internet browser lets you view the source of webpages you are browsing.

 

There is no reason that this line in your code should not work (but notice I changed it up a bit):

 

<?php
$imcolumn .= '<tr><td><img src="?pid='.$row[pid].'" width="144" /><br />';

 

However, the image will be distorted since you are not setting the height as well.

Link to comment
Share on other sites

no i cant veiw source either, well non other then aload of weird symbols that make no sense.

 

what server is it?

 

I think this is the confusion. Do you want to scale the image where it is embedded in web page.  Or do you want to scale the image whenever someone references it via "pics.php?pid=3"?

 

When I say view source, I mean view the source of "pics.php" without any GET variables in the url.

Link to comment
Share on other sites

good point flyhoney

 

i found this but there is no image showing to see what its outputing.

 

<html><head> 
<title>Selection of up to 3 images from a database</title> 
<style type="text/css">
<!--
.imgResize {
width:144px;
}
-->
</style>
<body bgcolor=white><h2> </h2> 
<font color=red></font> 
<center><table border=1> 
<b><tr><td>Images will appear here</td></tr></table></center> 
<hr> 

</body> 
</html> 

 

force an image to show then post link again and we will see what its outputting

Link to comment
Share on other sites

hey guys my script calls a picture in my database.they only thing is i need to resize it but it does not seem to work?

 

pics.php?pid=3

 

// Connect to database 

$errmsg = "";
if (! @mysql_connect("localhost","here","there")) {
$errmsg = "Cannot connect to database";
}
@mysql_select_db("techker_here");
// Find out about images to display 
$pid = mysql_escape_string($_GET['pid']);
if ($_GET['pid']) { 
   $whereclause = "where pid = \"$pid". 
      $_GET['pid']. 
      "$pid\""; 
   $gotten = @mysql_query("select * from pix  order by pid desc "); 
   while ($row = @mysql_fetch_assoc($gotten)) { 
      $imcolumn .= "<tr><td><img src=?pid=$row[pid] width=144 ><br>"; 
      $imcolumn .= htmlspecialchars($row[title])."</td></tr>"; 
      $nim++; 
   } 
   if (! $nim) $imcolumn = "<tr><td>No matching images</td></tr>"; 
} else { 
   $imcolumn .= "<tr><td>Images will appear here</td></tr>"; 
} 

// If this is the image request, send out the image 

if ($_GET['pid']) { 
   $gotten = @mysql_query("select * from pix where pid = $_GET[pid]"); 
   $row = mysql_fetch_assoc($gotten); 
   $bytes = $row[imgdata]; 
   header("Content-type: image/jpeg"); 
   print $bytes; 
   exit (); 
   } 

?> 

<html><head> 
<title>Selection of up to 3 images from a database</title> 
<body bgcolor=white><h2> </h2> 
<font color=red><?= $errmsg ?></font> 
<center><table border=1> 
<b><?= $imcolumn ?></table></center> 
<hr> 
</body> 
</html> 

 

 

The logic in this script is incorrect I'm guessing.  Notice that you have two blocks that start with if ($_GET['pid']).  This means the second block negates the first.  You need to revisit the logic flow of this script.

Link to comment
Share on other sites

What do you mean you cant view the source?  Every internet browser lets you view the source of webpages you are browsing.

 

There is no reason that this line in your code should not work (but notice I changed it up a bit):

 

<?php
$imcolumn .= '<tr><td><img src="?pid='.$row[pid].'" width="144" /><br />';

 

However, the image will be distorted since you are not setting the height as well.

 

it does not work the code is wrong.?

Link to comment
Share on other sites

Yes, but as I said before, it looks like that part of the code is meaningless because this part:

<?php
if ($_GET['pid']) { 
   $gotten = @mysql_query("select * from pix where pid = $_GET[pid]"); 
   $row = mysql_fetch_assoc($gotten); 
   $bytes = $row[imgdata]; 
   header("Content-type: image/jpeg"); 
   print $bytes; 
   exit (); 
} 
?>

 

prevents the $imcolumn string from ever being displayed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.