Question: Javascript Open Window / Dynamic Image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
tmaiden
Forum Commoner
Posts: 64
Joined: Fri Feb 24, 2006 3:15 pm
Location: Philadelphia
Contact:

Question: Javascript Open Window / Dynamic Image

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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.
Post Reply