1

I need to get the height and width properties from a .PNG File using VBScript.

I'm currently using loadpicture() which does well with other formats e.g. .JPG, .gifs, .ico, .bmp, and others. However, it does not support the .PNG file format.

The result I'm looking for is that the file is found and the height/width is returned. No other properties are needed.

Currently with loadpicture() it reports back with:

invalid file format

The code I am working with is:

  Set myImg = LoadPicture(imageName)
    imgWidth = Round(myImg.width / 26.4583)
    imgHeight = Round(myImg.height / 26.4583)
  Set myImg = Nothing

This works with many file formats. However, it does not work with .PNG

I must add that it is essential that I'm able to get height and width from .PNG files as the images are submitted by other users and they will need to be scaled so that they aren't overstretched/squished when resized.

I'm unfortunately unable to install any other programs to assist me with this but I'm wondering if it's possible using VBScript alone?

The difference for this question compared to older questions is that I'm unable to install or add third party software. I may possibly be able to get away with adding code files that originate as .txt but security is very tight. Thanks.

GhastlyCode
  • 248
  • 1
  • 11
  • `LoadPicture()` is not a built-in method in VBScript, can you show some code? Are you using a particular COM library in Classic ASP to provide this functionality? – user692942 Sep 13 '19 at 11:00
  • 1
    LoadPicture() Is infact built in to VBScript. I can update the question to show the code used but it honestly doesn't vary from what's already stated. – GhastlyCode Sep 13 '19 at 11:10
  • Do you mention you can't install any third-party because you're on a shared webhosting? If yes, just want to point out that most webhosts preinstall a range of third-party tools, you may want to look into that (check the FAQ or ask your host). If you're using a server component for your file uploads, there might be a built-in function that gives you file information (eg ASPupload) on the uploaded files. –  Sep 13 '19 at 11:10
  • @ChrisBE - That's useful to know but unfortunately the reason is for security and I don't have the permissions nor authority to do so. – GhastlyCode Sep 13 '19 at 11:12
  • @GhastlyCode your absolutely right, my bad never ever used it *(just double-checked the VBScript Scripting Reference and it's there)*. Always used 3rd party libraries like [ASPJpeg](http://www.aspjpeg.com/) to manipulate images in a Classic ASP environment. – user692942 Sep 13 '19 at 11:13
  • 2
    Did you stumble upon this code already? [http://www.4guysfromrolla.com/webtech/050300-1.shtml](http://www.4guysfromrolla.com/webtech/050300-1.shtml) –  Sep 13 '19 at 11:17
  • I had visited the page but it seems I skipped over the source code at the bottom. I'd been busy converting some VBA code in the meantime. I'll pop back here in a few moments once I've tested it out but that certainly looks promising! @Lankymart - No worries, by the looks of things many people aren't aware of its existance as my manager gave me the same answer when he looked at it earlier. – GhastlyCode Sep 13 '19 at 11:25
  • @ChrisBE - Just tested it and although it does bring back the file name, date created and the file size it doesn't bring back the width or height unfortunately... I'll keep playing around with it though. – GhastlyCode Sep 13 '19 at 11:48

0 Answers0