Tech Tip: Determining the picture type
PRODUCT: 4D | VERSION: 15.1 | PLATFORM: Mac & Win
Published On: February 11, 2016
The following method can determine the picture type either from a picture field or variable:
// -------------------------------------------------------------------------------- // Name: PICTURE_TYPE // Description: Method will determine what is the picture type. Return the // picture type as a long int. // // Input: // $1 (PICTURE) - Picture // Output: // $0 (LONGINT) - Picture Type (0-Undetermined, 1-JPEG, 2-BMP, 3-GIF, 4-PNG, // 5-TIFF, 6-SVG, 7-PICT, 8-4PCT, 9-EMF, 10-WDP, 11-ICON) // -------------------------------------------------------------------------------- C_PICTURE($1;$pic) C_LONGINT($0) C_BLOB($blob;$blob2) If (Count parameters=1) $pic:=$1 PICTURE TO BLOB($pic;$blob2;"") COPY BLOB($blob2;$blob;0;0;4) SET BLOB SIZE($blob2;0) Case of : (($blob{0}=255) & ($blob{1}=216)) // JPEG $0:=1 : (($blob{0}=66) & ($blob{1}=77)) // BMP $0:=2 : (($blob{0}=71) & ($blob{1}=73) & ($blob{2}=70)) // GIF $0:=3 : (($blob{0}=137) & ($blob{1}=80) & ($blob{2}=78)) // PNG $0:=4 : (($blob{0}=73)) & ($blob{1}=73) & ($blob{2}=42)) // TIFF $0:=5 : (($blob{0}=77)) & ($blob{1}=77) & ($blob{2}=0)) // TIFF $0:=5 : (($blob{0}=60)) & ($blob{1}=63) & ($blob{2}=120)) // SVG $0:=6 : (($blob{0}=54) & ($blob{1}=0)) // PICT $0:=7 : (($blob{0}=15)) & ($blob{1}=154) & ($blob{2}=0)) // 4PCT $0:=8 : (($blob{0}=1)) & ($blob{1}=0) & ($blob{2}=0)) // EMF $0:=9 : (($blob{0}=73)) & ($blob{1}=73) & ($blob{2}=188)) // WDP $0:=10 : (($blob{0}=0)) & ($blob{1}=0) & ($blob{2}=1)) // ICON $0:=11 Else $0:=0 // Not determined End case End if |
Example #1 of a picture variable that is a JPG type:
C_PICTURE($pic) C_LONGINT($type) $type:=PICTURE_TYPE($pic) // $pic is a JPG // $type=1 |
Example #2 of a picture field that is a SVG:
$type:=PICTURE_TYPE([Table_1]Picture) // record is a SVG // $type=6 |
F Hope this helps someone else (($blob{0}=37)