Announcement

Collapse
No announcement yet.

Is there a way to get the dimensions of a pre-existing image?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Is there a way to get the dimensions of a pre-existing image?

    The title says it all. Basically, is there a simple way to get the height and width of an existing image?

    MivaScript has gdImageSX and gdImageSY, but they don't work on saved image files; they only take the pointer to a new image being created.

    Which means a bit of overhead:
    1) Figure out what format the original image is in; JPG, GIF, PNG, etc
    2) Call the correct gdImageCreateFrom*() using the filename as source
    3) Do gdImageSY and SY on the new image and save the values
    4) gdImageDestroy

    Is there a more direct method?

    #2
    Re: Is there a way to get the dimensions of a pre-existing image?

    We have an Image_Dimensions function in lib/util_public.mv in the LSK that you can look at as an example (or just call directly). It reads the dimensions from supported file types directly, which is much faster than using GD, which has to load and decompress the image into memory.

    The parameters are:

    Image_Dimensions( filepath, location, width var, height var )

    Returns 1 on success, 0 on error.

    Comment


      #3
      Re: Is there a way to get the dimensions of a pre-existing image?

      Thanks, Burch.

      In looking at the LSK, it seems you're doing exactly what I plotted out, but through a number of function calls.

      However, I'm building this for a non-Merchant project so I will have to "unlearn" the code from the LSK and build it myself (unless the util functions really are publicly available). But it's good to know I was on the right track before looking at this.

      Comment

      Working...
      X