Resource

Resource Basics

Resource Name Dimensions in Inches
Resource Version 1.0
Category Custom Thumbnail Info
Downloads 765
Release Date 12/3/2019 6:21:23 PM
 

Resource Details

Description This script returns the dimension of an image in inches
Installation Instructions Add to the Custom Thumb Info
Usage Instructions n.a.
Changes in this version n.a.
Special Requirements
 

Author Information

Author Name IDimager Support
 

Available Attachments

Attachment #1 Dimensions in Inches.jpg
 

Script

%code
const
  cOutput = 'Inch';
  //cOutput = 'Centimeter';
var
  AWidthStr: String; AWidth: Double;
  AHeightStr: String; AHeight: Double;
  AXResStr: String; AXRes: Double;
  AYResStr: String; AYRes: Double;
  AResUnitStr: String;
  AResWidth: Double;
  AResHeight: Double;
begin
  result := '';

  AWidthStr  := StrTran('%ImageWidth', '.', DecimalSeparator);
  AHeightStr := StrTran('%ImageHeight', '.', DecimalSeparator);
  AXResStr   := StrTran('%exif:XResolution', '.', DecimalSeparator);
  AYResStr   := StrTran('%exif:YResolution', '.', DecimalSeparator);
  AResUnitStr := '%exif:ResolutionUnit';

  if IsValidNumberString(AWidthStr, False, '.') and
     IsValidNumberString(AHeightStr, False, '.') and
     IsValidNumberString(AXResStr, False, '.') and
     IsValidNumberString(AYResStr, False, '.')
  then
  begin
    AWidth   := StrToFloat(AWidthStr);
    AHeight  := StrToFloat(AHeightStr);
    AXRes    := StrToFloat(AXResStr);
    if AXRes = 0 then AXRes := 0.1;
    AYRes    := StrToFloat(AYResStr);
    if AYRes = 0 then AYRes := 0.1;

    result := AResUnitStr;

    if WideSameText(AResUnitStr, 'centimeter') then
    begin
      AResWidth := AWidth / (AXRes * 2.54);
      AResHeight := AHeight / (AYRes * 2.54);
    end
    else
    begin
      AResWidth := AWidth / AXRes;
      AResHeight := AHeight / AYRes;
    end

    if cOutput = 'Centimeter' then
      result := FloatToStr(RoundToPrecision(AResWidth*2.54, 2)) + 'cm x ' + FloatToStr(RoundToPrecision(AResHeight*2.54, 2)) + 'cm'
    else
      result := FloatToStr(RoundToPrecision(AResWidth, 2)) + '" x ' + FloatToStr(RoundToPrecision(AResHeight, 2)) + '"';
  end
  else
  begin
    if cOutput = 'Centimeter' then
      result := '?"" x ?"'
    else
      result := '?cm x ?cm'
  end;

  
//  %exif:XResolution
end;
%/code