Jump to content

Archived

This topic is now archived and is closed to further replies.

SieRobin

Image Resize

Recommended Posts

I've been looking into this for a few hours now and I can't seem to figure it out, so here I am asking you for help :P

Alright I have it set so you can upload one image which will be your profile image and your forum post image, how exactly do I set it so that it resizes the image in the forum so it doesn't pass 150x150? Pixels that is. Basically I want to do this so it doesn't show so huge, and rather just like a thumbnail.

Any provided information is appreciated.

Share this post


Link to post
Share on other sites
You could try the GD function imagecopyresampled() - Check the manual, it gives examples on its use.

Share this post


Link to post
Share on other sites
I had looked at the manual, but I still can't seem to figure it out, it just makes little sense to me, so if someone could make sense of it to me, I'd appreciate that lol. I guess all I want is something like this.

If the original size of the image succeeds 150x150 rescale the image so it's not over 150x150.

Share this post


Link to post
Share on other sites
you'll have to excuse my not explaining how this work... its something i put together about 18 months ago and have never gotten around to using properly.

It's all pretty straight forward...
$album is the subfolder within the images directory
$image is the filename of the image you want to work with

Both of these are to be specified in the URL. However, you can just ditch that and use the $img_name variable to specify it directly.

Hope this helps, sorry i can't be of any further use.


[code]
<?php
$album = $_GET['album'];
$image = $_GET['image'];

$img_name = "images/$album/$image";
$max_width    = 150; // maximum x aperture  in pixels
$max_height   = 150; // maximum y aperture in pixels
$size=GetImageSize($img_name);
$width_ratio  = ($size[0] / $max_width);
$height_ratio = ($size[1] / $max_height);

if($width_ratio >=$height_ratio)
{
   $ratio = $width_ratio;
}
else
{
   $ratio = $height_ratio;
}

$new_width    = ($size[0] / $ratio);
$new_height   = ($size[1] / $ratio);
Header("Content-Type: image/jpeg");
$src_img = ImageCreateFromJPEG($img_name);
$thumb = ImageCreateTrueColor($new_width,$new_height);
ImageCopyResampled($thumb, $src_img, 0,0,0,0,($new_width-1),($new_height-1),$size[0],$size[1]);
ImageJPEG($thumb);
ImageDestroy($src_img);
ImageDestroy($thumb);
?>
[/code]

Share this post


Link to post
Share on other sites
I get like a series of errors from that hehe.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: getimagesize(): Read error! in /home/sierobin/public_html/forum.php on line 76

Warning: Division by zero in /home/sierobin/public_html/forum.php on line 89

Warning: Division by zero in /home/sierobin/public_html/forum.php on line 90

Warning: Cannot modify header information - headers already sent by (output started at /home/sierobin/public_html/forum.php:7) in /home/sierobin/public_html/forum.php on line 91

Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in /home/sierobin/public_html/forum.php on line 92

Warning: imagecreatefromjpeg(): '/' is not a valid JPEG file in /home/sierobin/public_html/forum.php on line 92

Warning: imagecreatetruecolor(): Invalid image dimensions in /home/sierobin/public_html/forum.php on line 93

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/sierobin/public_html/forum.php on line 94

Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/sierobin/public_html/forum.php on line 95

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/sierobin/public_html/forum.php on line 96

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/sierobin/public_html/forum.php on line 97[/quote]

Share this post


Link to post
Share on other sites
Only the first message is relevant:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: getimagesize(): Read error! in /home/sierobin/public_html/forum.php on line 76[/quote]
This means the function couldn't read the input file in this line:
[code]<?php $size=GetImageSize($img_name); ?>[/code]
Does the variable $img_name contain a name of a valid file that the webserver can read?

All the other errors are caused by the first one.

Ken

Share this post


Link to post
Share on other sites
Ok so I changed around a few things that I thought were wrong just to see if that was it. But not I just get jibberish haha.

[code]$img_name = "userimages/$pstats3[uimage]";
$max_width    = 150; // maximum x aperture  in pixels
$max_height   = 150; // maximum y aperture in pixels
$size=getimagesize($img_name);
$width_ratio=($size[0] / $max_width);
$height_ratio =($size[1] / $max_height);

if($width_ratio>=$height_ratio)
{
   $ratio=$width_ratio;
}
else
{
   $ratio=$height_ratio;
}
$new_width=($size[0] / $ratio);
$new_height=($size[1] / $ratio);
header("Content-Type: image/jpeg");
$src_img = imagecreatefromjpeg($img_name);
$thumb = imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($thumb, $src_img, 0,0,0,0,($new_width-1),($new_height-1),$size[0],$size[1]);
imagejpeg($thumb);
imagedestroy($src_img);
imagedestroy($thumb);[/code]

And now I get this.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: Cannot modify header information - headers already sent by (output started at /home/sierobin/public_html/forum.php:7) in /home/sierobin/public_html/forum.php on line 89
ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ÿÛC    $.' ",#(7),01444'9=82<.342ÿÛC  2!!22222222222222222222222222222222222222222222222222ÿÀ–p"ÿÄ ÿĵ}!1AQa"q2?‘¡#B±ÁRÑð$3br‚ %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ ÿĵw!1AQaq"2?B‘¡±Á #3RðbrÑ $4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚâãäåæçèéêòóôõö÷øùúÿÚ ?ñ×¼ÂG#pù½ë¶ðì¬tx[<ÿú«Î”áJñŸS]w†u«T´k{‡y_6æ<J*ÄØén]±šM4yít»ð8ìN0??d˯Z^]­´d,g€äõ?áN:„nðC‹ò–YãÊ‘E ¿ $#­Ã»·ßù@U5ÓØxžî$¶²û,Mµn,Fp:Õ½B1lWÇåYö—1ËGRÀÁö¢ì Æ? ýô÷Þx€Hw2ã æ? øbyµ¬»ãt¤+?£&¢½»{‹§¶g ª÷ší<˜·!$"ˆ¯¾÷~ÔîÀžíì|9bÖ–r(¼`åÆJúŸ¯µsƒ[±šXmͺ•Œœ3O½Kñk{Y-Ø M¬iàŽ¾õÃÚÜ¡ygâ_,n(3ó{}*æÜÖ.ÛÚéÖr4FÚ!¿;‹€{ÕkýNÎÙð‹†7¡®^ok•†Þ xXã=*µÕËÜD²ÜFë3®xà~T(XrškCÛt Ë[½%Ýc?8 ¨1ÍQñeô/áÍ^¸?XÏ¿Ë ˆÆÃÉ?ä×'àÅض¹A hÎv#¿ó®çÄ6Ë‚µ± !PX\p‹€0?T™“V>}–ßlÊ#?!»U?P9q[Í1C–©ã×5Bm6czˆ#lI’¼uÖªè’nZÙîãvÝ ¦9Á­ë«#oáø¦¶W[Ÿ•²¼ê*¾œÃOŽE•E‘—äÇ+Œûzÿ*šêý¢?¯HØd NVØ¿µšM7«#ä#Ÿ^5wJK+{…pÌÚÁœýÜqŠ«a2ÞÈa0?'߇봛íZ#w%†8¬ÜŸa—¦HÞúg6àîürió´Î|°ÊÝ´½kÌäiaòߎ0xæ»ëry±]2o6ÁÇÿZš–š‰nTø™e-ÛÚÞZ?2Î5òðˆ@V'ò9öô¬ÏCm§C{y|„™"ò£B¹Ü-úq^…âè[Tðìñ[Ã1)‰lÀãë\4"óÃp[Gù‘Hw»6ý SoKW½rK_ XÞB÷ö ʪÄÝxÏ\dô®X‘ä¾_5@)…Àé]nž÷²[2¬Ñý?6E?_ë\þ¯nÏ2¾ß›nO×5)êiR:hoøî ؆`|çÃ°È W§xÓP³‡Ázä-u;é÷ ¨\I?°¯(ðv?šŸ‰míîIùaŸõ¯@Õô‹¼âKhÊC§Ü´E†H!>µ´‡,÷<»N”.•$¦Ú) ·'fOoñ«7ú”šžŸäÍj± tÄcËÚG~¿…/‡Q—ú²„ÊËù/øVÆ?iw«êŽb³Šm±ÈäFÁüëI7{#4Ž+N‰eŸ÷²(Sœ—ëÒ£Õ­[ÊŽdÃD¼ s‘]cøhéºÜ×7N‘2 ’;xFåÉ0$ôÛ5?«y×zu²ÛÆ1òq…ÉDZ’.Ú†µ?DÒ‚Í Ïy:~ò@7}?N+ŸÔngÕ¯{gg‘¾Dþµ`Es‘HÕO\±'¥užœM¨Éx¯˜Ô9$š‡±¬9^Œæo,5=!ѯí&€`€Ädcê)ÚþÝVíСgŽsÞ½{Ô•ž‰)26· þÈ‹ M'Ä6ב[ù?ÌYç ýÑS)­…RŸ³g±¼Ó½¹c|2àïu^õç—Öqè¼²Émþ‹qóß?8Îx®†?Z3GX\‚ÜcƒÏjÝñî‚óéQ^2m I$wöç5j- Œ¬ÎAo亶IÒùV5ÀÅb_´NFU»+{†±T‚ÐɳŒÆ3?­hiÚ×W.›ÊV`6/$þ=ªãFO¡r¬­©—£Iwoâ8ÐÞY??œšô+øcƒÀþ#_)Òâ]&áØ°?6#lŸÌ×M¢øGL°’+¨"ÍÂ?ªÝ‡©÷5oÆPÇÃïùi?ý—t>¿ºj¾NSI=?ÑæŠ2þÒxÂ4LËÈàgð¬áâµðåÁº³E2¾GÊÝ0k]l–ûM¾±t?¾œ»I‘?ò®Vo ¤r0h™ u9Ãg<ñÅgæÇ´´4µÛýsXš`Ö 2HªÛã—iÆäÇ¥X´¿Óì5hmnmä?"o”¸`}y­Ë}$±3Bbdn0à ?Ö¤?O -Ãy6ònbwhÏN™?•91$yþ¿µÞ¤ÒéÖo dôÆpSZÞO"ÒâR¢G …† â·žæÆêèY­Œ-8ùSl`gÔ`¾ž½¼/s·I ‰$Û´˜ZÇ?ü&ñ£ozLäµûß+R†¸üj˜£†×}ÊÄNG”Eü[­[Õ<-«I­Ú¬³Zy×2ùqªJòqÐ3Eö?6•y4{ß>ß5×,æ´§FÆ5åÍ;ô=áÝ­î§yÅÍåµÝ…²|¦=¬wö qœŽ¿•zV­¥?WOxØ)Àëžð¶‘ÿ×… …Ô ‡>dåGñ7oÃ?]¾­f#\.ñÔfºc–†w¹æ³xbm þhò¤8lgƒèkOÃk_j‹!Söx~fÀàžÀšíç—KÔ£•ãuo¼­ÐÔðEi+S þ V¾Óݵ‰åÖäØc€¸¦¬OœxÄj: .çÿE5oÇØŽk˜ñÌËÿ/ˆÔžN?sÿ¢š±µÊ<®òê 2öéVɈÜÂA–àrrsÞ¬h·ÖÚ„¾]¼2FËPýk–ñ>¿m©ÐÌÒÛ?xÆ*_k–¦WNC•?xàuéXkÔë”ir®W©èkm|ž8â?·*ŒŠÏˆþêi´%?Å?¦jLùY™¯ÙCo"ßÚÒlà…zšå.¯.l.AI™†îÆOô®×R™ï UÝö츽9® Q´¸ŸP[pv0ÈÜÁˆ?&¥é$ËWähuÃêsj’Çn‹*£nIÀêEkxwE½Ö5TkØdŠiG‘˜Äíüj_èZÔn"™ÞHI@Ÿ‹c5Õ_ßG¥Z hOÍŽOrjÜ»wÕ?.­­Å4DZÌVnŒ€þ•nÛEÓÖ6¹†X¥e?Xõ¯5±²»Ö¯’ÀÊGlÜpkÙ"M?,R«|£ÅuB|ÈÆqQzEѼ ­tí?âß‚~¸ø{G+ò^\)õgúVŠÛ[+d*“î)åÑGÊ‘ñÛZ÷ Å}ÕŠ–Óu†“òÎ\k›ñ^¬n<#®Át<«¡ap öÝ·"º›ùT¡ßlý×Á¯;ñ£$žÕ†åZM‚í¸caïMè‚×<Ä7«ªÞ]¤…Ñä%K ;VˆÖ´ø¢†=*(”€K¯-øší5ŸévË,Fâ+­Äº vÀí\ì>±±›Éh®Bzë\Ü—FžÒÍŽ·ÔÛ`(ì¹íšë4]\eK…3`|¬Ëœrx¬¸|;7ï´éœÂP+rÖK8ÂÅáÈøþ'¹lŸÈÔJ?úš*¦´¦?Üáôn*È×4øòc1/©¬fšÞNC€ÛËÿ?`kwz?"íZÝŸøc•ŸÔƒKÙù•í‘×]xš§Ë?®'WÖ²í<§$ðŠ;ÔÖma¨ØÛËs8óÆ×'"´.ôH"µ,¶_iD9oÖ…˜JµÑ7ƒnŽ·wai(¦åe•OC³ŸÇ½{2ÚÉü{Þ2ŽË!ÈÕƒáXh¢çÊÅܪ sÄy꿽t3D—?¥_ï!ä×DtÐçnär´¾€J¿ß„üß•eÝN€ñ3nôa´þµ<çOLæ{«vúY³_Z¯ ]ö| Õ¢vBîóq+ÃEä×-â8Ùô a?Yq§Ü¹ÿVÝ«®’íYIUÔ.Gr±ñÅs^"ºy¼3¯(¶6ð?:”¦ >[u'©¨¨ô*+QZämCïU5½:(4?í7,×°Ùƒ€€ÔÒK©Ø"á®#'Ñy¨5½zÂûC†Ê"D9$Ž:Ô¾ÄNQ¶å¯˜`IÏ$U{íF+ ×R¬q?Õ?'è+2ëÅZ”±… À.ó?Ä{ ó­WV»Õ/ ÷?–G°¨p”_¼R’{.¥ãGrÉcÅ?òÑúþUÉÞ\Ë+½Ì?#0Á$Õ4zÒ‚=iÙ Óð¾³6‡tù?^'Jç;ƒ_Eø> -CGƒUŽUœÊ¼ «nàû×Ïú…µ?IºÖ?ƒ†šN}=kÙü+¡Éá?1íc¾•üÒðp¹öªy£v\a)-IL§S•>´ÉÂãågOu5Å^\Ë ×Aì\Ô ~íÏŸ ›Í/n»}]÷:ùR÷º¸½·(j¡;jƒ9ž(ǨLW?öÆQÄÎ>ŽE'ÚÃrò÷cšX]…õ~ìÑx¤µÖ©3‘üòOôÎx£x𦹻"?°NK?êÛ©­{ÏÍX~*¿?¼-« aóYL?ñÃYʬ¥¡¢¥«ž`÷dã,y¨Ì¬N3úÖH› J—'×èûKž_! × ÈíÍf]ÏîÏ?²zŽC…V™Ì“œ“í@5„çÌmس¥é·Z¶¡ ?ªo–S€:©>•ê:Ã;;B³êl.åˆ×ˆÇøÒ|?ðèÓ¬—S¹\]Ý©)ê‘÷?Ž+®{µ†5?d}ˆ×Ë9»ÙÔ©+^Eø"ŽÚ5ŽTU  õòZÆrrõ‘{®­?ו, ÊãåQZz†`×mî}VF…¸+ lç¸ÜsúT¨6Tê(œÍή·2B6ž@íP?jÊ3´Ý°>›I¯M±ðÎ?¦Ä¢+;~?Ž\1?‰«’Ï¥Ù&[ìè÷TUû$cíÙäm­[»tÿ÷é¿ÂªÜk.¨|©KÀJô{ÿiÖÙ[t?°®~çÄÚ¾¤JB« g¹â?f?ÖgúõÛp šÏÕõ+ÉtkÕu`­€ñþÉ®ÒmíäÎBäcŽ¬{XÞ œÅ¡êKq )ÚJ#Á{iÜžýk6Ô]†œ¤Žz%˜i§Ö’;u.Ñõë–¹H`¸t‚v™ù]—nGÒ»~+½rè*ÏåY§¸$“êk3þKl|×îõÅw*S8ÝHÖy¯i¦ÿY²µ"Y‘OÓ<Óu+ìë?ýêFCŠ·áiÒßÄvsH芌Ig8ƒÞ²’hÖ“G­Çªª^jR;–ª!Œvªú†±nš¦›ó±w9÷!N+’Ó5%½·×ðÁ¼ÉASž£dU][VE}'QGL(LžA5ÏÊw9ér—‰5ù‰Öæ åŽèA¯Hð÷Å{iôÄ·û BaP¥WzWˆj—)qª<‘°eÆÁ|°Û?Ç#ÚŠ+3NgkªH5ÔøgÄúfŽ#ûT/‰·¿–ªr¼qËCEq܆M¯x³JÔ#–;.ãF?8"Œxá?bE«Û¨!£~xÝ€HLÑEŽãÞ/ð?©-õ–µ{r9!¢?Ëéæsø×t>?xYWjéÚÀP0†/þ9E†ŽK[øÇo¬3/‘y¿ðÄqøüÜ×#¨ø¶ÊúÒá WY#dMʸ\ŒzÑE [/quote]

Share this post


Link to post
Share on other sites
The gibberish is really the picture being displayed as printable characters. The error saying [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: Cannot modify header information - headers already sent by (output started at /home/sierobin/public_html/forum.php:7) [/quote] is the reason. What is on line 7 of forum.php?

How are you invoking the script to display the image?

Ken

Share this post


Link to post
Share on other sites
Line 7 is just <?php

Uhmn basically I'm just posting the image, with an HTML tag, <img src and such. How should I do it?

Share this post


Link to post
Share on other sites
Please post the code you're using. Do you have anything before the "<?php"?

Ken

Share this post


Link to post
Share on other sites
when you use a valid image, this script does work. I've just tested it with an image thats on my own domain... from my local machine.

[code]
<?php
$img_name = "http://www.wisewood.org/blog/images/burger.jpg";
$max_width    = 100; // maximum x aperture  in pixels
$max_height   = 100; // maximum y aperture in pixels
$size=GetImageSize($img_name);
$width_ratio  = ($size[0] / $max_width);
$height_ratio = ($size[1] / $max_height);

if($width_ratio >=$height_ratio)
{
   $ratio = $width_ratio;
}
else
{
   $ratio = $height_ratio;
}

$new_width    = ($size[0] / $ratio);
$new_height   = ($size[1] / $ratio);
Header("Content-Type: image/jpeg");
$src_img = ImageCreateFromJPEG($img_name);
$thumb = ImageCreateTrueColor($new_width,$new_height);
ImageCopyResampled($thumb, $src_img, 0,0,0,0,($new_width-1),($new_height-1),$size[0],$size[1]);
ImageJPEG($thumb);
ImageDestroy($src_img);
ImageDestroy($thumb);
?>
[/code]

Share this post


Link to post
Share on other sites
Yes there is script before <?php and this is what is shown.

[code]<?php
session_start();
include 'connect.php';
?>
<link rel="stylesheet" href="style.css" type="text/css">
<title>Feudal Age - Forum</title>[/code]

The script I have is shown as this.

[code]$img_name = "userimages/$pstats3[uimage]";
$max_width    = 150; // maximum x aperture  in pixels
$max_height   = 150; // maximum y aperture in pixels
$size=getimagesize($img_name);
$width_ratio=($size[0] / $max_width);
$height_ratio =($size[1] / $max_height);

if($width_ratio>=$height_ratio)
{
   $ratio=$width_ratio;
}
else
{
   $ratio=$height_ratio;
}
$new_width=($size[0] / $ratio);
$new_height=($size[1] / $ratio);
header("Content-Type: image/jpeg");
$src_img = imagecreatefromjpeg($img_name);
$thumb = imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($thumb, $src_img, 0,0,0,0,($new_width-1),($new_height-1),$size[0],$size[1]);
imagejpeg($thumb);
imagedestroy($src_img);
imagedestroy($thumb);[/code]

Share this post


Link to post
Share on other sites
The way this script is written, you should be invoking it something like this:
[code]
<img src="yourscripthere.php?fn=<?echo userimages/$pstats3['uimage'] ?>">
[/code]
Then in [b]yourscripthere.php[/b]
[code]<?php
session_start();
if (isset($_GET['fn'])) {
   $img_name = $_GET['fn'];
//
// etc...
//
   imagedestroy($thumb);
   exit();
}
?>[/code]

Ken

Share this post


Link to post
Share on other sites
Ah, well the way I need it done is to be inserted into a forum. Everyone has a picture next to their name when they post a message, so how would it still be done?

Share this post


Link to post
Share on other sites
Please post all of you code so we can see what you're doing.

Ken

Share this post


Link to post
Share on other sites
Ok this is what's in forum.php, I prefer to keep my forums all in one page, it just saves me time.

[code]<?php
session_start();
include 'connect.php';
?>
<link rel="stylesheet" href="style.css" type="text/css">
<title>Feudal Age - Forum</title>
<?php
include "navigate.php";
if (isset($_SESSION['player']))
  {
  $player=$_SESSION['player'];
  $userstats="SELECT * from users where playername='$player'";
  $userstats2=mysql_query($userstats) or die("Could not retrieve the users stats.");
  $userstats3=mysql_fetch_array($userstats2);
  $brd=$_GET['brd'];
  $msg=$_GET['msg'];
  $thread="SELECT * from f_thread where bname='$brd' AND ID='$msg' order by timep DESC";
  $thread2=mysql_query($thread) or die ("Could not display threads");
  $thread3=mysql_fetch_array($thread2);        
  $pstats="SELECT * from users where ID='$thread3[UID]'";
  $pstats2=mysql_query($pstats) or die("Could not display quote");
  $pstats3=mysql_fetch_array($pstats2);        
  $post="SELECT * from f_post where bname='$brd' AND msg='$msg' order by ID ASC";
  $post2=mysql_query($post) or die ("Could not display threads");
  $post3=mysql_fetch_array($post2);
  $reply=$_POST['reply'];
  $title=$_POST['title'];
  $postr=$_POST['post'];
  $sreply=$_POST['sreply'];  
  $spost=$_POST['post'];
  $titlet=$_POST['titlet'];
  $postt=$_POST['postt'];
  $sthread=$_POST['sthread'];
  $delete=$_GET['del'];
  $deletet=$_GET['del'];
  $nowtime=time();
if (isset($deletet)) {
    print "<table class='table'><tr class='headline'><td align='center'>Delete</td></tr>
    <tr class='mainrow'><td align='center'>You have successfully deleted your thread.<br>
    <a href='forum.php?brd=$brd'>Back To Board</a></tr></td></table>";
    mysql_query("DELETE from f_thread where ID='$deletet'") or die ("Could not delete.");
    mysql_query("DELETE from f_post where msg='$deletet'") or die ("Could not delte.");
    }
elseif (isset($delete)) {
    print "<table class='table'><tr class='headline'><td align='center'>Delete</td></tr>
    <tr class='mainrow'><td align='center'>You have successfully deleted your reply.<br>
    <a href='forum.php?brd=$brd'>Back To Board</a></tr></td></table>";
    mysql_query("DELETE from f_post where ID='$post3[ID]'") or die ("Could not delete.");
    }
elseif (isset($sthread)) {
    print "<table class='table'><tr class='headline'><td align='center'>Reply</td></tr>
    <tr class='mainrow'><td align='center'>Your thread has been posted.<br>
    <a href='forum.php?brd=$brd'>Back To Board</a></tr></td></table>";
    mysql_query("INSERT f_thread set author='$userstats3[playername]', UID='$userstats3[ID]', title='$titlet', post='$postt', bname='$brd', timep='$nowtime'") or die ("Could not post reply");
    }
elseif (isset($sreply)) {
    mysql_query("UPDATE f_thread set replies=replies+1, lastpost='$userstats3[playername]', LUID='$userstats3[ID]', timep='$nowtime' where bname='$brd' AND ID='$msg'") or die("Could not log views");
    print "<table class='table'><tr class='headline'><td align='center'>Reply</td></tr>
    <tr class='mainrow'><td align='center'>Your reply has been posted.<br>
    <a href='forum.php?brd=$brd&msg=$msg'>Back To Thread</a><br>
    <a href='forum.php'>Back To Forum</a></tr></td></table>";
    mysql_query("INSERT f_post set author='$userstats3[playername]', UID='$userstats3[ID]', title='$title', post='$postr', bname='$brd', msg='$msg', timep='$nowtime'") or die ("Could not post reply");
        }  
  elseif (isset($msg)) {
          mysql_query("UPDATE f_thread set views=views+1 where bname='$brd' AND ID='$msg'") or die("Could not log views");
          $post="SELECT * from f_post where bname='$brd' AND msg='$msg' order by ID ASC";
        $post2=mysql_query($post) or die ("Could not display threads");
        print "<table class='table'><tr class='headline'><td colspan='2'><center>Forum</center></td></tr>
        <tr class='mainrow'><td bgcolor='ababab' width='20%' rowspan='2' class='mainrowf'><a href='profile.php?id=$thread3[UID]'>";
        if ($pstats3['uimage']=="") {
        print "<center><font color='green'>No Photo</font></center>";
        } else {
        print "<center><img src='image.php?img=userimages/$pstats3[uimage]' border='0'></center><br>";
        }
        print "$thread3[author]</a><br>
        Race: $pstats3[race]<br>Level: $pstats3[level]</td><td class='mainrowb'>$thread3[title]</td></tr>
        <tr class='mainrow'><td>$thread3[post]<br>";
        if ($userstats3['ID']==$thread3['UID']) {
        print "<div align='right'>[<a href='forum.php?brd=$brd&del=$thread3[ID]'>Delete</a>]";
        }
        print "<hr width='80%'>
        $pstats3[quote]</td></tr>
        <tr height='10' class='headline'><td colspan='2'></td></tr>";
        while  ($post3=mysql_fetch_array($post2)) {
        $stats="SELECT * from users where ID='$post3[UID]'";
          $stats2=mysql_query($stats) or die("Could not display quote");    
          $stats3=mysql_fetch_array($stats2);
        print "<tr class='mainrow'><td bgcolor='ababab' width='20%' rowspan='2' class='mainrowf'><a href='profile.php?id=$post3[UID]'>";
        if ($stats3['uimage']=="") {
        print "<center><font color='green'>No Photo</font></center>";
        } else {
        print "<center><img src='image.php?img=userimages/$stats3[uimage]' border='0'></center><br>";
        }
        print "$post3[author]</a><br>
        Race: $stats3[race]<br>Level: $stats3[level]</td><td class='mainrowb'>$post3[title]</td></tr>
        <tr class='mainrow'><td>$post3[post]<br>";
        if ($userstats3['ID']==$post3['UID']) {
        print "<div align='right'>[<a href='forum.php?brd=$brd&msg=$msg&del=$post3[ID]'>Delete</a>]";
        }
        print "<hr width='80%'>
        $stats3[quote]</td></tr>
        <tr height='10' class='headline'><td colspan='2'></td></tr>";
        }
        print "</table><br>
        <table class='otable'><tr class='headline'><td><center>Reply</center></td></tr>
        <tr class='mainrow'><td><form name='reply' method='post'>Title: <input type='text' size='59' name='title' value='None'><br>
        <textarea cols='65' rows='9' name='post'></textarea><br>
        <div align='right'><input type='submit' name='sreply' value='Reply'></div></td></tr></table></form>";
          }
    elseif (isset($brd)) {  
         $thread="SELECT * from f_thread where bname='$brd' order by timep DESC";
          $thread2=mysql_query($thread) or die ("Could not display threads");  
        print "<table class='table'><tr class='headline'><td colspan='5'><center>Forum</center></td></tr>
        <tr><td class='mainrowb'>Thread</td><td class='mainrowb'>Author</td><td class='mainrowb'>Last Poster</td><td class='mainrowb'>Replies</td><td class='mainrowb'>Views</td>";
        while ($thread3=mysql_fetch_array($thread2)) {
        print "<tr class='mainrow'><td><a href='forum.php?brd=$brd&msg=$thread3[ID]' title='$thread3[post]'>$thread3[title]</a></td>
        <td><a href='profile.php?id=$thread3[UID]'>$thread3[author]</center></td><td><a href='profile.php?id=$thread3[LUID]'>$thread3[lastpost]</a></td><td>$thread3[replies]</td>
        <td>$thread3[views]</td></tr>";
        }
        print "</table><br>
        <table class='otable'><tr class='headline'><td align='center'>New Thread</td></tr>
        <tr class='mainrow'><td><form name='thread' method='post'>Title: <input type='text' size='59' name='titlet'><br>
        <textarea cols='65' rows='9' name='postt'></textarea><br>
        <div align='right'><input type='submit' name='sthread' value='Post Thread'></div></td></tr></table></form>";
        } else {
    $forum="SELECT * from f_forum order by ID ASC";
    $forum2=mysql_query($forum) or die("Could not retrieve the users stats.");
    print "<table class='table'><tr class='headline'><td colspan='4'><center>Forum</center></td></tr>
    <tr><td class='mainrowb'>Board Name</td><td class='mainrowb'>Description</td></tr>";
    while ($forum3=mysql_fetch_array($forum2)) {
    print "<tr class='mainrow'><td><a href='forum.php?brd=$forum3[bname]'>$forum3[fname]</a></td><td>$forum3[desc]</td></tr>";
    }
    $last="SELECT * FROM f_post ORDER BY timep DESC limit 5";
    $last2=mysql_query($last) or die(mysql_error());
    print "</table>
    <br><table><tr><td><table class='left'><tr class='headline'><td colspan='2'>Last Replies</td></tr>
    <tr><td class='mainrowb'>Title</td><td class='mainrowb'>Author</td></tr>";
    while ($last3=mysql_fetch_array($last2)) {
    print "<tr class='mainrow'><td><a href='forum.php?brd=$last3[bname]&msg=$last3[msg]'>$last3[title]</a></td><td><a href='profile.php?id=$last3[UID]'>$last3[author]</a></td></tr>";
      }
    $lastt="SELECT * FROM f_thread ORDER BY ID DESC limit 5";
    $lastt2=mysql_query($lastt) or die(mysql_error());
    print "</td></tr></table><td><table class='right'><tr class='headline'><td colspan='2'>Last Threads</td></tr>
    <tr><td class='mainrowb'>Title</td><td class='mainrowb'>Author</td></tr>";
    while ($lastt3=mysql_fetch_array($lastt2)) {
    print "<tr class='mainrow'><td><a href='forum.php?brd=$lastt3[bname]&msg=$lastt3[ID]'>$lastt3[title]</a></td><td><a href='profile.php?id=$lastt3[UID]'>$lastt3[author]</a></td></tr>";
      }
    print "</tabe></td></tr></table>";
    }
  }
?>[/code]

Now I have a new php file created named image.php, this is what it contains.

[code]<?php
session_start();
if (isset($_GET['img'])) {
$img_name = "userimages/$pstats3[uimage]";
$max_width    = 150;
$max_height   = 150;
$size=getimagesize($img_name);
$width_ratio=($size[0] / $max_width);
$height_ratio =($size[1] / $max_height);

if($width_ratio>=$height_ratio)
{
   $ratio=$width_ratio;
}
else
{
   $ratio=$height_ratio;
}
$new_width=($size[0] / $ratio);
$new_height=($size[1] / $ratio);
header("Content-Type: image/jpeg");
$src_img = imagecreatefromjpeg($img_name);
$thumb = imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($thumb, $src_img, 0,0,0,0,($new_width-1),($new_height-1),$size[0],$size[1]);
imagejpeg($thumb);
imagedestroy($src_img);
imagedestroy($thumb);
exit();
}
?>[/code]

Share this post


Link to post
Share on other sites
The source looks ok. Look at the generated HTML to see if the <img> tag is being created correctly.

Ken

Share this post


Link to post
Share on other sites
All I did was change what you put into what was needed for the img tag. Ehmn, but let me double check it.

What I don't get is how is image.php associated with forum.php when it really isn't being a link clicked for the $_GET situation?

Share this post


Link to post
Share on other sites
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]What I don't get is how is image.php associated with forum.php when it really isn't being a link clicked for the $_GET situation?[/quote]

This code in the <img> tag is what invokes the script.
[code]<img src='image.php?img=userimages/$stats3[uimage]' border='0'>[/code] with the get method.

Ken

Share this post


Link to post
Share on other sites
Doesn't seem to be working though, or else I suppose it would be pulling the information from the file.

I don't have to do an include do I?

Share this post


Link to post
Share on other sites
Did you do this:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Look at the generated HTML to see if the <img> tag is being created correctly.[/quote]

If the generated code references image.php with the correct parameters, you will have to add debug statements to image.php. These can't write the information to the screen, but will have to write to a files.

[a href=\"http://www.rutgerspromenaders.org/pictures/index.php?d=./dances/2006/0402\" target=\"_blank\"]This[/a] site that I wrote uses a similar mechanism. It's a picture gallery, but the concept is the same. If you do a "show source" and scroll down towards the end you will see the <img> tags.

Ken

Share this post


Link to post
Share on other sites

×

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.