Jump to content
Sign in to follow this  

Graphic Dimensions

Recommended Posts

Is it possible to get the width and height attributes from a graphic file? I've looked through the help file but I've come up with nothing. I'm attempting to create a script which will look at the current graphic size and then modify it within an HTML document. The modification will be easy - I just can't seem to figure out how to figure out the original dimensions. :whistle:

Thank you,


Share this post

Link to post
Share on other sites

Don't think it can be done with AutoIt itself, but why do you need to know this for formatting your HTML file ?

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
Live for the present,
Dream of the future,
Learn from the past.

Share this post

Link to post
Share on other sites

I know it sounds like a strange request. Basically, what I am doing is creating a javascript pop-up message when people log onto their computers. I will not be entering any data into the script - this is something Marketing will do so the script needs to be bulletproof.

So far, I have it set up so regular text can be entered and then it will be formatted to work within the javascript code. I'm able to enter website links as well. However, if the Marketing person wants to insert a picture, that's when things go wrong.

Inserting a picture is no problem, but I'm afraid that she will choose a picture that is too large for the pop-up window (currently set at 250 x 500 pixels) so I want to be able to get the picture width and then do some math to get it down to around 200 pixels and then reduce the height by the same ratio. Then all I have to do is throw in some <width=..., height=...> tags using the variables and I've got my reduced picture.

The only problem is getting the size of the picture in the first place.

Thank you,


Share this post

Link to post
Share on other sites

since you are doing it in Java, maybe you can use javascript to give you the size. Here is a little code from javascript.internet.com


  1.  Copy the coding into the HEAD of your HTML document
  2.  Add the onload event handler into the BODY tag
  3.  Put the last coding into the BODY of your HTML document  -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document  -->


 .divstyle{position:absolute; width="0";height:"0"}

<script LANGUAGE="Javascript">

<!-- This script and many more are available free online at -->
<!-- The Javascript Source!! http://javascript.internet.com -->

<!-- Begin
function showimg(form)
adres = form.image_file.value;
index = adres.indexOf(".gif");
index = index + adres.indexOf(".jpg");
index = index + adres.indexOf(".bmp");
if (form.image_file.value == "")
  {alert("No Image found!");}
  {if (index == -3){alert("Unknow image type");
    var img_obj = new Image();
    img_obj = form.image_file.value;
    document.changing.src = img_obj;
    document.changing2.src= img_obj;
    document.changing.width = document.changing2.width;
    document.changing.height = document.changing2.height;
fast = 0;
change = 0;
function upw(){
function over_upw(){upw();
  change = 1;
  changetime = setTimeout("fast_upw()","600");}
function fast_upw(){clearTimeout(changetime);
  fast = setTimeout("fast_upw()","100");}
function clt(){
if (change == 1){clearTimeout(changetime);}
change = 0;
function resize()  {document.changing.height = document.image.height.value;
  document.changing.width = document.image.width.value;}
function downw(){document.image.width.value=parseInt(document.image.width.value)-1;
function over_downw(){downw();
  change = 1;
  changetime = setTimeout("fast_downw()","600");}
function fast_downw(){clearTimeout(changetime);
  fast = setTimeout("fast_downw()","100");}
function uph(){document.image.height.value=parseInt(document.image.height.value)+1;
function over_downh(){downh();
  change = 1;
  changetime = setTimeout("fast_downh()","600");}
function fast_downh(){clearTimeout(changetime);
  fast = setTimeout("fast_downh()","100");}
function over_uph(){uph();
  change = 1;
  changetime = setTimeout("fast_uph()","600");}
function fast_uph(){clearTimeout(changetime);
  fast = setTimeout("fast_uph()","100");}
function downh(){document.image.height.value=parseInt(document.image.height.value)-1;
function set(){
//  End -->


<!-- STEP TWO: Insert the onload event handler into your BODY tag  -->

<BODY onload="set()">

<!-- STEP THREE: Copy this code into the BODY of your HTML document  -->

<form name="image">
<input type="file" name="image_file"><br><br>
<input type="button" name="show" value="Show image" onclick="showimg(this.form)">
Width   Heigth
<br><img src="/img/image-resizer/up.gif" onmousedown="over_upw()" onmouseup="clt()">
<img src="/img/image-resizer/down.gif" onmousedown="over_downw()" onmouseup="clt()">
<input type="text" name="width" size="4" readonly>
<input type="text" name="height" size="4" readonly>
<img src="/img/image-resizer/up.gif" onmousedown="over_uph()" onmouseup="clt()" >
<img src="/img/image-resizer/down.gif" onmousedown="over_downh()" onmouseup="clt()">
<table border ="2">
<img src="/img/image-resizer/1.gif" name="changing">
<div STYLE="left:-5000 px;top:0" class="divstyle">
<P ><img src="/img/image-resizer/1.gif" name="changing2"></p>

<font face="arial, helvetica" size"-2">Free Javascripts provided<br>
by <a href="http://javascriptsource.com">The Javascript Source</a></font>

<!-- Script Size:  4.09 KB -->

Only a start, but you can display Java results in the titlebar, and AutoIt can read that, so you could make a script to do this, although I think there are much cleaner methods, perhapse a commandline program.

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post

Link to post
Share on other sites

Good God! B)

That's a lot of code, scriptkitty! The javascript that I am using is actually the output file. I'm using javascript to create an HTML window which can resize itself, give itself a static position and most importantly, get rid of the toolbar/menubar. What I am doing is taking text input using Notepad and then formatting that text and sending it to a *.js file. When the user logs on, they run "wscript.exe javascript.js" and it creates an HTML window on their screen.

I'll probably just find a 3rd party application which can work behind the scenes (command line prog) to find the width/height of a graphic.

I'm amazed at how much AutoIt can do already ... I really can't expect it to do everything! :whistle:


Share this post

Link to post
Share on other sites

Comandline version and description:

There is a collection of commandline utilities at:


In there is a tiny one called Identify, which can give you back what you need.

# identify -format "%wx%h" sample.png

ImageMagick is available for free, may be used to support both open and proprietary applications, and may be redistributed without fee.

There are other nice things like an image resizer from the command line.

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post

Link to post
Share on other sites

Thanks again, scriptkitty.

I had downloaded ImageMagick and tried the Identify executable but I never tried the -format option. I used -size without any luck and gave up on it. The -format option works perfectly.

It would appear the script I created is going to work perfectly thanks to AutoIt and all the help I received from the forums.



Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...