shocker-z Posted May 15, 2006 Share Posted May 15, 2006 How would i go about making a script that could put an image on coordinates but an image from a data base..My current code is[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php if ($_GET['id']) {function hexrgb ($hexstr,$img_handle){ $int = hexdec($hexstr); list($r, $g, $b) = array(0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int); return (ImageColorAllocate($img_handle, $r, $g, $b));}include('/var/www/profiles/library/opendb.php');include('/var/www/countdown/countdown.php');$id=$_GET['id'];header ("Content-type: image/png");$getcount=mysql_query("SELECT date, bgcolor FROM count WHERE `id` = '$id'");$date_r=mysql_fetch_array($getcount);$date=$date_r['date'];list($year, $month, $day) = split("-", $row['date']);$count_days=countdown($day,$month,$year);$im = @ImageCreateFromPNG ("php.png"); if(!$im) { $img_handle = ImageCreate (200, 60) or die ("Error, image not created"); $back_color = hexrgb($date_r['bgcolor'],$img_handle); $txt_color = hexrgb($txtcolor,$img_handle); $textquery=mysql_query("SELECT * FROM count_data WHERE countid = '$id'");while ($text=mysql_fetch_array($textquery)) { $txtcolor = hexrgb($text['color'],$img_handle); ImageString ($img_handle, $text['size'], $text['countx'], $text['county'], $text['text'], $txtcolor);} ImagePng ($img_handle);}Else { }}else {}?>[/quote]And this basicaly grabs text and the posisions from a database and displays the text where the user wants it to go.. What i also need is a way i can place an image from a database store as BLOB inside the image i generate above.This is just a litle playaround atm.. Have a go at the text based one atmLogin with info below:Site: [a href=\"http://www.ukchat.ws\" target=\"_blank\"]http://www.ukchat.ws[/a] User: testPass: userthen click "Add Countdown" And you will see what i'm on bout and maby an idea of how it will work..RegardsLiam Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted May 15, 2006 Share Posted May 15, 2006 the test seems to work fine -- doing exactly what you say it should.adding an image from a database should be relitively easy, no? imagecreatefromstring($myrow['image']) should get it loaded. then you can just do an imagecopyresampled, or just an imagecopy to get it on your current image.I have some thumbnail code if you need it. Quote Link to comment Share on other sites More sharing options...
shocker-z Posted May 15, 2006 Author Share Posted May 15, 2006 Simple as that! :smiley:Cheers mate!I have some already that i use for the profiles but if u post yours too then i can choose the best :) just been coding in notepad from work for past few weeks and adding things just to make the day go by and thought this would be good idea as a novalty also goin to add img width and height so people can add then to forums and so on..Liam Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted May 15, 2006 Share Posted May 15, 2006 I wrote this myself, but it's been tested and should be free of bugs.[code]<?php$myrow=mysql_fetch_assoc(mysql_query("SELECT * FROM `table` WHERE ..."));if (strlen($myrow['image'])>0) $im=imagecreatefromstring($myrow['image']);else $im=imagecreatefrompng("generic.png"); // if no image, use generic image.$width=100; //max width$height=100; //max heightif(imagesx($im)>imagesy($im)) { //if landscape orentation if(imagesx($im)<=$width) { //if image is smaller than max width, just copy it. $newim=imagecreatetruecolor(imagesx($im),imagesy($im)); imagecopy($newim,$im,0,0,0,0,imagesx($im),imagesy($im)); } else { // image is larger than maximum, resize. $newim=imagecreatetruecolor($width,((imagesy($im)/imagesx($im))*$width)); imagecopyresampled($newim,$im,0,0,0,0,$width,((imagesy($im)/imagesx($im))*$width),imagesx($im),imagesy($im)); }} else { // image is portrait orentation (or perfectly square) if(imagesy($im)<=$height) { // image is smaller than max height, just copy it. $newim=imagecreatetruecolor(imagesx($im),imagesy($im)); imagecopy($newim,$im,0,0,0,0,imagesx($im),imagesy($im)); } else { //image is larger, resize. $newim=imagecreatetruecolor(((imagesx($im)/imagesy($im))*$height),$height); imagecopyresampled($newim,$im,0,0,0,0,((imagesx($im)/imagesy($im))*$height),$height,imagesx($im),imagesy($im)); }}imagedestroy($im);?>[/code]$newim is the starting point for whatever else you want to do. Quote Link to comment Share on other sites More sharing options...
shocker-z Posted May 16, 2006 Author Share Posted May 16, 2006 It's showing totaly blank mate :SI have definatly got the data in the table as i can view the image through the site on profiles [a href=\"http://www.ukchat.ws/profiles/thumbs.php?id=5\" target=\"_blank\"]http://www.ukchat.ws/profiles/thumbs.php?id=5[/a]code:[code]<?phpinclude('../library/header.php');$myrow=mysql_fetch_assoc(mysql_query("SELECT * FROM `images` WHERE id = '5'"));if (strlen($myrow['content'])>0) $im=imagecreatefromstring($myrow['content']);else $im=imagecreatefrompng("generic.png"); // if no image, use generic image.$width=100; //max width$height=100; //max heightif(imagesx($im)>imagesy($im)) { //if landscape orentation if(imagesx($im)<=$width) { //if image is smaller than max width, just copy it. $newim=imagecreatetruecolor(imagesx($im),imagesy($im)); imagecopy($newim,$im,0,0,0,0,imagesx($im),imagesy($im)); } else { // image is larger than maximum, resize. $newim=imagecreatetruecolor($width,((imagesy($im)/imagesx($im))*$width)); imagecopyresampled($newim,$im,0,0,0,0,$width,((imagesy($im)/imagesx($im))*$width),imagesx($im),imagesy($im)); }} else { // image is portrait orentation (or perfectly square) if(imagesy($im)<=$height) { // image is smaller than max height, just copy it. $newim=imagecreatetruecolor(imagesx($im),imagesy($im)); imagecopy($newim,$im,0,0,0,0,imagesx($im),imagesy($im)); } else { //image is larger, resize. $newim=imagecreatetruecolor(((imagesx($im)/imagesy($im))*$height),$height); imagecopyresampled($newim,$im,0,0,0,0,((imagesx($im)/imagesy($im))*$height),$height,imagesx($im),imagesy($im)); }}imagedestroy($im);?>[/code]table:Field name - Typeid - int(11)name - varchar(30)type - varchar(30)size - int(11) content - mediumblobusername - varchar(30)description - varchar(254) YesRegardsLiam Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted May 16, 2006 Share Posted May 16, 2006 Well, the code assumes you're going to do something else with the image, so there is no display. Just for grins, I've added the appropriate display lines at the bottom.[code]<?phpinclude('../library/header.php');$myrow=mysql_fetch_assoc(mysql_query("SELECT * FROM `images` WHERE id = '5'"));if (strlen($myrow['content'])>0) $im=imagecreatefromstring($myrow['content']);else $im=imagecreatefrompng("generic.png"); // if no image, use generic image.$width=100; //max width$height=100; //max heightif(imagesx($im)>imagesy($im)) { //if landscape orentation if(imagesx($im)<=$width) { //if image is smaller than max width, just copy it. $newim=imagecreatetruecolor(imagesx($im),imagesy($im)); imagecopy($newim,$im,0,0,0,0,imagesx($im),imagesy($im)); } else { // image is larger than maximum, resize. $newim=imagecreatetruecolor($width,((imagesy($im)/imagesx($im))*$width)); imagecopyresampled($newim,$im,0,0,0,0,$width,((imagesy($im)/imagesx($im))*$width),imagesx($im),imagesy($im)); }} else { // image is portrait orentation (or perfectly square) if(imagesy($im)<=$height) { // image is smaller than max height, just copy it. $newim=imagecreatetruecolor(imagesx($im),imagesy($im)); imagecopy($newim,$im,0,0,0,0,imagesx($im),imagesy($im)); } else { //image is larger, resize. $newim=imagecreatetruecolor(((imagesx($im)/imagesy($im))*$height),$height); imagecopyresampled($newim,$im,0,0,0,0,((imagesx($im)/imagesy($im))*$height),$height,imagesx($im),imagesy($im)); }}imagedestroy($im);header("Content-type: image/jpeg");imagejpeg($newim,"",90);?>[/code] Quote Link to comment Share on other sites More sharing options...
haydndup Posted May 16, 2006 Share Posted May 16, 2006 Would [a href=\"http://scudworkz.com/php_tutorials/mysql_image_storing/\" target=\"_blank\"]this[/a] be of any help? Although probably not if you can already see the images on thumbs.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.