Jump to content

layering images


JaneMN

Recommended Posts

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.

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

something like this might work  :confused:

 


<?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);

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.