Image File resolution

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Image File resolution

    hi,

    I m currently facing this problem: if i wanna use CFFILE to capture an image
    file, in jpg or gif format, how do i know its resolution, for example, 640 x
    480.

    my work now is to restrict the over-resoluton file to upload to the system, so
    i would like to find out what is the best way to identify the image file
    resolution and reject this file.

    need advise from u guyz, thanx in advanced

    spawninc Guest

  2. Similar Questions and Discussions

    1. Image resolution
      I am trying to print a collage of images on one sheet of paper. When I size my image, how come it appears bigger than it should when I transfer it to...
    2. CFDocument - Image Resolution
      Hey All, I am generating PDF's using CFDocument. All the html type looks excellent, crisp and clean in the PDF's, however any images in the PDF...
    3. set of resolution for an image
      Hi, I'm looking for a way to set the dpi parameter of an image in order to control the size of the print out knowing the height and the width of...
    4. Image resolution on import
      I have open an RGB AICS document. I link-place a 72ppi JPG. Now ALL that's in the file is a line of Point type and this JPG (whose file size is 80...
    5. Image resolution changes automatically.
      Greetings Tony, For a better understanding of resolution, I suggest you review an excellent article on the subject. Please visit the Digital Dog...
  3. #2

    Default Re: Image File resolution

    If you're running MX+, you could use of the [url]http://java.sun.com/products/java-media/jai/[/url]
    BSterner Guest

  4. #3

    Default Re: Image File resolution

    If you're running MX+, you could use of the [url]http://java.sun.com/products/java-media/jai/[/url]. I know you can extract the height and width. Not sure about the resolution.

    BSterner Guest

  5. #4

    Default Re: Image File resolution

    i only hv less control on the server, therefore i will try to use a script to
    control the image file instead. I will restrict the image file that its width
    is more than 300 pixl to upload to the server, so how can i achieve this?

    spawninc Guest

  6. #5

    Default Re: Image File resolution

    pls help... still looking for solution
    spawninc Guest

  7. #6

    Default Re: Image File resolution

    Hi Spawninc

    Im afraid I dont know a way of rejecting the image before it is uploaded -
    once uploaded thou you could check the width and height of the file with the
    following udf:

    -------------------------------------------------------------------------------
    <cfscript>
    /**
    * Returns width and height of images based on image type.
    *
    * @param filename Absolute or relative path to file. (Required)
    * @param mimetype Minetype for the file. (Optional)
    * @return Returns a struct containing height and width information, or an
    error string.
    */
    function ImageSize(filename) {
    // Jpeg variables
    var nFileLength=0; var nBlockLength=0; var nMarker=0;
    var nSOI = 65496; // Start of Image (FFD8)
    var nEOI = 65497; // End of Image (FFD9)
    var nSOF = 65472; // Start of frame nMarker (FFC0)
    var nSOF1 = 65473; // Start of frame extended sequential mode (FFC1)
    var nSOF2 = 65474; // Start of frame progressive mode (FFC2)
    var nSOF3 = 65475; // Start of frame lossless mode (FFC3)
    var nSOS = 65498; // Start of Scan (FFDA)


    var sImageType = "";
    var kCoords = structNew();
    var fInput = 0;
    var sByte=0;
    var sFullPath="";
    var sMimeType = "";

    if (Left(filename,1) IS "/" OR Left(filename,1) IS "\" OR MID(filename,2,1)
    IS ":")
    sFullPath=filename;
    else
    sFullPath=ExpandPath(filename);

    // Establish image type
    if(arrayLen(arguments) gt 1) { //optional mimetype
    sMimeType = arguments[2];
    if (LCase(ListFirst(sMimeType,"/")) IS NOT "image") return "Wrong mime type";
    if (ListLen(sMimeType,"/") NEQ 2) return "Invalid mime type";
    sImageType=LCase(ListLast(sMimeType,"/"));
    } else { // work off file extension
    if (ListLen(filename,".") LT 2) return "Unknown image type";
    sImageType=LCase(ListLast(filename,"."));
    }

    if(not fileExists(sFullPath)) return "File does not exist.";

    //make a fileInputStream object to read the file into
    fInput = createObject("java","java.io.RandomAccessFile").in it(sFullPath,"r");

    // Get X,Y resolution sizes for each image type supported
    switch (sImageType) {
    case "jpg": case "jpeg":
    do {
    nMarker = fInput.readUnsignedShort();

    if (nMarker NEQ nSOI AND nMarker NEQ nEOI AND nMarker NEQ nSOS) {

    nBlockLength = fInput.readUnsignedShort();

    if (nMarker EQ nSOF OR nMarker EQ nSOF1 OR nMarker EQ nSOF2 OR nMarker EQ
    nSOF3) { // Start of frame
    fInput.readUnsignedByte(); // skip sample precision in bits
    kCoords.ImageHeight = fInput.readUnsignedShort();
    kCoords.ImageWidth = fInput.readUnsignedShort();
    fInput.close();
    return kCoords;
    } else {
    fInput.skipBytes(JavaCast("int",nBlockLength-2));
    }
    }
    } while (BitSHRN(nMarker,8) EQ 255 AND nMarker NEQ nEOI);
    break;
    case "gif":
    fInput.skipBytes(6);

    sByte = fInput.readUnsignedByte();
    kCoords.ImageHeight = fInput.readUnsignedByte() * 256 + sByte;

    sByte = fInput.readUnsignedByte();
    kCoords.ImageWidth = fInput.readUnsignedByte() * 256 + sByte;

    fInput.close();
    return kCoords;
    default:
    break;
    }
    //close out this entry
    fInput.close();
    return "Unhandled image type";
    }
    </cfscript>


    <CFSCRIPT>
    kImageSize = ImageSize("D:/Your_Path/Image.jpg");
    </CFSCRIPT>

    <CFOUTPUT>
    #kImageSize.ImageWidth#
    #kImageSize.ImageHeight#
    </CFOUTPUT>


    --------------------------------------------------------------------------------
    -------
    Hope this helps in some way ;)

    Thanks hose

    bleachedBug Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139