Page 1 of 1

Question: Javascript Open Window / Dynamic Image

Posted: Tue Apr 18, 2006 11:23 am
by tmaiden
I have a javascript function on a page, addimage.php, which opens a new window.

Code: Select all

<SCRIPT LANGUAGE="JavaScript"> 
<!-- 
...
win = window.open('previewimage.php','', 'toolbar=0, location=0, directories=0, status=0, scrollbars=0, menubar=0');
} 
//--> 
</script>
This is in the window which it opens, 'previewimage.php'

Code: Select all

<?php 
        header("Content-type: image/jpeg");
        ...
        $im = imagecreate(460,90);
        $bg = imagecolorallocate($im,$bg1,$bg2,$bg3);
        $fg = imagecolorallocate($im,$tc1,$tc2,$tc3);
        $borc = imagecolorallocate($im,$bc1,$bc2,$bc3);
        imagefill($im,0,0,$bg);
        imagerectangle($im,0,0,460,90,$borc);
        imagestring($im,3,6,7,"Blah Blah Blah",$fg);
        $startdate = date("F j, Y, g:i a");
        imagestring($im,3,6,19,"'$title' - Started On $startdate",$fg);
        imagestring($im,3,6,31,"Total Times Read - 872346",$fg);
        imagejpeg($im);
        imagedestroy($im);
?>
This all works fine. What I don't like is, the image gets scaled down and/or resized. How can I prevent this from happening?
Is it possible to make the window open to the exact size of the image, no matter what size the image is?
And, how would I do so?

Thanks.

Posted: Tue Apr 18, 2006 11:36 am
by RobertGonzalez
Can you get the dimensions of the image in the first page and pass that to your javascript call as the window dimensions? Then when the window opens you don't have to fidget with the dimensions of the image at all because they were already set in the calling page.

Posted: Tue Apr 18, 2006 11:37 am
by hawleyjr
Possible attributes for window.open:
* width
* location
* scrollbars
* height
* directories
* resizable
* toolbar
* status
* menubar
All you need to do is set the height and width to what is desired.