JaneMN Posted August 8, 2011 Share Posted August 8, 2011 OK, I am frustrated and a beginner. tested query, its pulling correct results. tested layers[] its getting correct results (file path) dir structure myscript/mnMap/images.png tested file path via long code as in this: $layers = array(); $layers[] = imagecreatefrompng("mnMap/Anoka_County.png"); $layers[] = imagecreatefrompng("mnMap/Aitkin_County.png"); $layers[] = imagecreatefrompng("mnMap/Becker_County.png"); $im = imagecreatefrompng("mnmap/MN_counties_blank.png"); plus a couple lines of code here and image displays correctly. Below is the code I am trying to get to work. while ($layer = mysql_fetch_row($sql)){ for($i=0;$i<sizeof($layer);$i++) $layers[]= ($layer[$i]); //tested this with print_r and working } //line19 foreach ($layers as $value) {$j=0;$j<sizeof($value);$j++; $newLine = imagecreatefrompng($value); $im =imagecreatefrompng("mnMap/MN_counties_blank.png"); imagecopy($im, $newLine[$i], 0, 0, 0, 0, 500, 569); } header("Content-Type: image/png"); imagepng($im); I get a bunch of characters like I opened something with the wrong program below the error list. errors: Warning: imagecreatefrompng("mnMap/Aitkin.png") [function.imagecreatefrompng]: failed to open stream: No such file or directory in [fullpath to script] on line 22 Warning: imagecopy(): supplied argument is not a valid Image resource in [fullpath to script] on line 24 The above warnings repeat for the 2nd image in the query. mnMap directory is there and permission 755 Warning: imagecopy(): supplied argument is not a valid Image resource in [full path to script] on line 24 Warning: Cannot modify header information - headers already sent by (output started at full path to script) on line 26 NOTE: path is entered as "mnMaps/Anoka.png" in DB. I tried multiple ways of DB entry in attempts to get this working but not typing in full path as in /home/mydir/myscript/mnMaps/Anoka.png, plus all other script edits over the last two days. Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/244275-layering-images/ Share on other sites More sharing options...
jcbones Posted August 8, 2011 Share Posted August 8, 2011 You are getting the header error, because of the Warnings. Which is also why you see 'characters'. I can not fix file path errors for you, all I can do is tell you to: 1. make sure that the file path is from the directory that the file is in, relative file path (not recommended, for reasons already posted). or, 2. give the script the absolute file path (recommended). Quote Link to comment https://forums.phpfreaks.com/topic/244275-layering-images/#findComment-1254629 Share on other sites More sharing options...
JaneMN Posted August 9, 2011 Author Share Posted August 9, 2011 You are getting the header error, because of the Warnings. Which is also why you see 'characters'. I can not fix file path errors for you, all I can do is tell you to: 1. make sure that the file path is from the directory that the file is in, relative file path (not recommended, for reasons already posted). or, 2. give the script the absolute file path (recommended). OK, thanks for the suggestions but it didnt work (assuming I understood the suggestion correctly). I moved the files into the same directory as the script, checked the php.ini for base dir, tried full path in DB, http path in DB. I am still stumped. Quote Link to comment https://forums.phpfreaks.com/topic/244275-layering-images/#findComment-1254655 Share on other sites More sharing options...
darkfreaks Posted August 9, 2011 Share Posted August 9, 2011 something like this might work <?php // config -- $src = array ("http://www.google.com/images/logo_sm.gif", "http://sk2.php.net/images/php.gif"); $under = 0; // combine images underneath or not? // -- end of config $imgBuf = array (); $maxW=0; $maxH=0; foreach ($src as $link) { switch(substr ($link,strrpos ($link,".")+1)) { case 'png': $iTmp = imagecreatefrompng($link); break; case 'gif': $iTmp = imagecreatefromgif($link); break; case 'jpeg': case 'jpg': $iTmp = imagecreatefromjpeg($link); break; } if ($under) { $maxW=(imagesx($iTmp)>$maxW)?imagesx($iTmp):$maxW; $maxH+=imagesy($iTmp); } else { $maxW+=imagesx($iTmp); $maxH=(imagesy($iTmp)>$maxH)?imagesy($iTmp):$maxH; } array_push ($imgBuf,$iTmp); } $iOut = imagecreate ($maxW,$maxH) ; $pos=0; foreach ($imgBuf as $img) { if ($under) imagecopy ($iOut,$img,0,$pos,0,0,imagesx($img),imagesy($img)); else imagecopy ($iOut,$img,$pos,0,0,0,imagesx($img),imagesy($img)); $pos+= $under ? imagesy($img) : imagesx($img); imagedestroy ($img); } imagegif($iOut); Quote Link to comment https://forums.phpfreaks.com/topic/244275-layering-images/#findComment-1254683 Share on other sites More sharing options...
JaneMN Posted August 10, 2011 Author Share Posted August 10, 2011 something like this might work Thanks for this code. Will experiment to see if I can get something started working. Work kept me too busy yesterday to test. Quote Link to comment https://forums.phpfreaks.com/topic/244275-layering-images/#findComment-1255215 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.