Page 1 of 1

Code shows Image in binary in one page but not in other?

Posted: Sun Oct 09, 2005 2:39 am
by rxsid
Hi all,

I've got what appears to me to be some strange behaving code, although I'm sure someone will look at it and inform me....no, here's your issue. I hope ;)

this chunck is part of a 'parent' page and is the page that displays the images' in binary format:

Code: Select all

$imgPath = "/home/somesite/public_html/somedir/photos/".$photo;
    $fp = fopen($imgPath, "r");
    $imageFile = fread ($fp, 300000);
    fclose($fp);

    $tmpfname = tempnam ("../imagesTMP", "IMG");

    $fp = fopen($tmpfname, "w");
    fwrite($fp, $imageFile);
    fclose($fp);

    $photoInfo=GetImageSize($imgPath);

    if ($photoInfo[2]=="1") {
        $im_old = imageCreateFromGif($tmpfname);
    } elseif ($photoInfo[2]=="2") {
        $im_old = imageCreateFromJpeg($tmpfname);
    } elseif ($photoInfo[2]=="3") {
        $im_old = imageCreateFromPng($tmpfname);
    }

    //**** Delete Temporary File ****
    unlink($tmpfname);

    $th_max_width = 1.5 * $photoInfo[0];
    $th_max_height = 1.5 * $photoInfo[1];

    $ratio = ($width > $height) ? $th_max_width/$photoInfo[0] :
    $th_max_height/$photoInfo[1];
    $th_width = $photoInfo[0] * $ratio;
    $th_height = $photoInfo[1] * $ratio;
    $im_new = imagecreatetruecolor($th_width,$th_height);
    imageAntiAlias($im_new,true);

    $th_file_name = $photoDir;
    imageCopyResampled($im_new,$im_old,0,0,0,0,$th_width,$th_height,
    $photoInfo[0], $photoInfo[1]);

    if ($photoInfo[2]=="1") {
        imageGif($im_new,$th_file_name,100);
    } elseif ($photoInfo[2]=="2") {
        imageJpeg($im_new,$th_file_name,100);
    } elseif ($photoInfo[2]=="3") {
        imagePng($im_new,$th_file_name);
    }

//then the image is displayed here with a link
echo "<a href=\"../photos/$photo\" onClick=\"return enlarge('../photos/$photo',event)\"><img name=\"tnImage\" src=\"../photos/$photo\" border=\"0\" alt=\"ENLARGE THIS PHOTO\"></a>";
now, the above code works excellent if i delete it out of the parent page and put it in another page that is opened in a new window (child window) from the parent page.

Code: Select all

echo "<a href=\"http://somesite.com/somedir/enlargeTEST.html?photo=$photo\" target=\"enlarge\" onmouseover=\"window.status='ENLARGE THIS PHOTO';return true;\" onmouseout=\"window.status=' ';return true;\" onClick=\"window.open('enlargeTEST.html?photo=$photo', 'enlagre', 'status=yes,menubar=no,scrollbars=yes,height=275,width=300,resizable=no'); return false\"><img src=\"..//../photos/$photo\" border=\"0\" alt=\"ENLARGE THIS PHOTO\"></a>";
//This code works excellent.
So I'm basically just 'enlarging' the image by 1.5x
I want to be able to use the first code because I want to utilize the JS stuff that happens there and not open a new, second window. I know the JS works fine if I cut out the PHP image code stuff. So the JS isn't the issue.

Why would the PHP image code spit out the image in binary in the first example, but work perfectly in the second example (same code, just in a new child window)??

Thanks

Posted: Sun Oct 09, 2005 11:13 am
by feyd
$photoDir doesn't appear to be set anywhere in your code. Additionally, your code appears to rely on register globals is this true?

Posted: Mon Oct 10, 2005 12:22 am
by rxsid
thanks for the reply.

$photoDir is set further up. i've posted a small snippet of the larger code. also, i'm using extract() on the post, and i interigate all expected var's to specs, if something is found that doesn't belong, or doesn't fit the specs, it's ignored and/or the post is rejected.

what about the difference in behaviour in the php code? it's the exact same code used in either the parent or the child (i've tried both...but not concurrently of course), but the results are very different as described. why?