techker Posted November 16, 2008 Share Posted November 16, 2008 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 https://forums.phpfreaks.com/topic/132932-image-size/ Share on other sites More sharing options...
.josh Posted November 16, 2008 Share Posted November 16, 2008 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 https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691257 Share on other sites More sharing options...
techker Posted November 16, 2008 Author Share Posted November 16, 2008 the script works great.the only thing i need is to output a smaller image. Link to comment https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691260 Share on other sites More sharing options...
laPistola Posted November 16, 2008 Share Posted November 16, 2008 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 https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691287 Share on other sites More sharing options...
gevans Posted November 16, 2008 Share Posted November 16, 2008 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 https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691312 Share on other sites More sharing options...
techker Posted November 16, 2008 Author Share Posted November 16, 2008 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 https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691384 Share on other sites More sharing options...
techker Posted November 16, 2008 Author Share Posted November 16, 2008 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 https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691432 Share on other sites More sharing options...
laPistola Posted November 16, 2008 Share Posted November 16, 2008 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 https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691495 Share on other sites More sharing options...
techker Posted November 16, 2008 Author Share Posted November 16, 2008 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 https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691527 Share on other sites More sharing options...
laPistola Posted November 16, 2008 Share Posted November 16, 2008 Have you tried $imcolumn .= "<tr><td><img src=?pid=$row[pid] class=imgResize ><br>"; then in css .imgResize { width:144px; } Link to comment https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691544 Share on other sites More sharing options...
laPistola Posted November 16, 2008 Share Posted November 16, 2008 have you viewed the source to check what its doing on output Link to comment https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691547 Share on other sites More sharing options...
techker Posted November 16, 2008 Author Share Posted November 16, 2008 Have you tried $imcolumn .= "<tr><td><img src=?pid=$row[pid] class=imgResize ><br>"; then in css .imgResize { width:144px; } doesn't work..very good idea do.. and i can't view the source..lol http://tech-design.info/pics.php?pid=28 Link to comment https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691556 Share on other sites More sharing options...
flyhoney Posted November 16, 2008 Share Posted November 16, 2008 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 https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691559 Share on other sites More sharing options...
laPistola Posted November 16, 2008 Share Posted November 16, 2008 no i cant veiw source either, well non other then aload of weird symbols that make no sense. what server is it? Link to comment https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691560 Share on other sites More sharing options...
laPistola Posted November 16, 2008 Share Posted November 16, 2008 However, the image will be distorted since you are not setting the height as well. if you only set one of the axis it auto scales Link to comment https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691561 Share on other sites More sharing options...
flyhoney Posted November 16, 2008 Share Posted November 16, 2008 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 https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691566 Share on other sites More sharing options...
laPistola Posted November 16, 2008 Share Posted November 16, 2008 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 https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691569 Share on other sites More sharing options...
flyhoney Posted November 16, 2008 Share Posted November 16, 2008 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 https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691573 Share on other sites More sharing options...
flyhoney Posted November 16, 2008 Share Posted November 16, 2008 If you want to resize the image on the fly, you will need to use the PHP GD image manipulation library (if you have it installed). Link to comment https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691578 Share on other sites More sharing options...
techker Posted November 16, 2008 Author Share Posted November 16, 2008 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 https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691581 Share on other sites More sharing options...
flyhoney Posted November 16, 2008 Share Posted November 16, 2008 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 https://forums.phpfreaks.com/topic/132932-image-size/#findComment-691584 Share on other sites More sharing options...
techker Posted November 17, 2008 Author Share Posted November 17, 2008 why is that? Link to comment https://forums.phpfreaks.com/topic/132932-image-size/#findComment-692097 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.