Skip to content

Commit

Permalink
Replace piexifjs with piexif-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed Feb 9, 2025
1 parent de911cb commit e5839fa
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 348 deletions.
10 changes: 5 additions & 5 deletions IsraelHiking.Web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion IsraelHiking.Web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"osmtogeojson": "^3.0.0-beta.5",
"pbf": "^3.2.1",
"photoswipe": "^5.4.4",
"piexifjs": "1.0.6",
"piexif-ts": "^2.1.0",
"platform": "^1.3.6",
"pmtiles": "^3.0.7",
"proj4": "^2.12.0",
Expand Down
320 changes: 0 additions & 320 deletions IsraelHiking.Web/src/application/models/non-typed-modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,323 +10,3 @@ declare module "file-saver-es" {
const saveAsFunction: typeof saveAs;
export { saveAsFunction as saveAs };
}

declare module "piexifjs" {
const ImageIFD = {
ProcessingSoftware = 11,
NewSubfileType = 254,
SubfileType = 255,
ImageWidth = 256,
ImageLength = 257,
BitsPerSample = 258,
Compression = 259,
PhotometricInterpretation = 262,
Threshholding = 263,
CellWidth = 264,
CellLength = 265,
FillOrder = 266,
DocumentName = 269,
ImageDescription = 270,
Make = 271,
Model = 272,
StripOffsets = 273,
Orientation = 274,
SamplesPerPixel = 277,
RowsPerStrip = 278,
StripByteCounts = 279,
XResolution = 282,
YResolution = 283,
PlanarConfiguration = 284,
GrayResponseUnit = 290,
GrayResponseCurve = 291,
T4Options = 292,
T6Options = 293,
ResolutionUnit = 296,
TransferFunction = 301,
Software = 305,
DateTime = 306,
Artist = 315,
HostComputer = 316,
Predictor = 317,
WhitePoint = 318,
PrimaryChromaticities = 319,
ColorMap = 320,
HalftoneHints = 321,
TileWidth = 322,
TileLength = 323,
TileOffsets = 324,
TileByteCounts = 325,
SubIFDs = 330,
InkSet = 332,
InkNames = 333,
NumberOfInks = 334,
DotRange = 336,
TargetPrinter = 337,
ExtraSamples = 338,
SampleFormat = 339,
SMinSampleValue = 340,
SMaxSampleValue = 341,
TransferRange = 342,
ClipPath = 343,
XClipPathUnits = 344,
YClipPathUnits = 345,
Indexed = 346,
JPEGTables = 347,
OPIProxy = 351,
JPEGProc = 512,
JPEGInterchangeFormat = 513,
JPEGInterchangeFormatLength = 514,
JPEGRestartInterval = 515,
JPEGLosslessPredictors = 517,
JPEGPointTransforms = 518,
JPEGQTables = 519,
JPEGDCTables = 520,
JPEGACTables = 521,
YCbCrCoefficients = 529,
YCbCrSubSampling = 530,
YCbCrPositioning = 531,
ReferenceBlackWhite = 532,
XMLPacket = 700,
Rating = 18246,
RatingPercent = 18249,
ImageID = 32781,
CFARepeatPatternDim = 33421,
CFAPattern = 33422,
BatteryLevel = 33423,
Copyright = 33432,
ExposureTime = 33434,
ImageResources = 34377,
ExifTag = 34665,
InterColorProfile = 34675,
GPSTag = 34853,
Interlace = 34857,
TimeZoneOffset = 34858,
SelfTimerMode = 34859,
FlashEnergy = 37387,
SpatialFrequencyResponse = 37388,
Noise = 37389,
FocalPlaneXResolution = 37390,
FocalPlaneYResolution = 37391,
FocalPlaneResolutionUnit = 37392,
ImageNumber = 37393,
SecurityClassification = 37394,
ImageHistory = 37395,
ExposureIndex = 37397,
TIFFEPStandardID = 37398,
SensingMethod = 37399,
XPTitle = 40091,
XPComment = 40092,
XPAuthor = 40093,
XPKeywords = 40094,
XPSubject = 40095,
PrintImageMatching = 50341,
DNGVersion = 50706,
DNGBackwardVersion = 50707,
UniqueCameraModel = 50708,
LocalizedCameraModel = 50709,
CFAPlaneColor = 50710,
CFALayout = 50711,
LinearizationTable = 50712,
BlackLevelRepeatDim = 50713,
BlackLevel = 50714,
BlackLevelDeltaH = 50715,
BlackLevelDeltaV = 50716,
WhiteLevel = 50717,
DefaultScale = 50718,
DefaultCropOrigin = 50719,
DefaultCropSize = 50720,
ColorMatrix1 = 50721,
ColorMatrix2 = 50722,
CameraCalibration1 = 50723,
CameraCalibration2 = 50724,
ReductionMatrix1 = 50725,
ReductionMatrix2 = 50726,
AnalogBalance = 50727,
AsShotNeutral = 50728,
AsShotWhiteXY = 50729,
BaselineExposure = 50730,
BaselineNoise = 50731,
BaselineSharpness = 50732,
BayerGreenSplit = 50733,
LinearResponseLimit = 50734,
CameraSerialNumber = 50735,
LensInfo = 50736,
ChromaBlurRadius = 50737,
AntiAliasStrength = 50738,
ShadowScale = 50739,
DNGPrivateData = 50740,
MakerNoteSafety = 50741,
CalibrationIlluminant1 = 50778,
CalibrationIlluminant2 = 50779,
BestQualityScale = 50780,
RawDataUniqueID = 50781,
OriginalRawFileName = 50827,
OriginalRawFileData = 50828,
ActiveArea = 50829,
MaskedAreas = 50830,
AsShotICCProfile = 50831,
AsShotPreProfileMatrix = 50832,
CurrentICCProfile = 50833,
CurrentPreProfileMatrix = 50834,
ColorimetricReference = 50879,
CameraCalibrationSignature = 50931,
ProfileCalibrationSignature = 50932,
AsShotProfileName = 50934,
NoiseReductionApplied = 50935,
ProfileName = 50936,
ProfileHueSatMapDims = 50937,
ProfileHueSatMapData1 = 50938,
ProfileHueSatMapData2 = 50939,
ProfileToneCurve = 50940,
ProfileEmbedPolicy = 50941,
ProfileCopyright = 50942,
ForwardMatrix1 = 50964,
ForwardMatrix2 = 50965,
PreviewApplicationName = 50966,
PreviewApplicationVersion = 50967,
PreviewSettingsName = 50968,
PreviewSettingsDigest = 50969,
PreviewColorSpace = 50970,
PreviewDateTime = 50971,
RawImageDigest = 50972,
OriginalRawFileDigest = 50973,
SubTileBlockSize = 50974,
RowInterleaveFactor = 50975,
ProfileLookTableDims = 50981,
ProfileLookTableData = 50982,
OpcodeList1 = 51008,
OpcodeList2 = 51009,
OpcodeList3 = 51022,
NoiseProfile = 51041,
};


const ExifIFD = {
ExposureTime = 33434,
FNumber = 33437,
ExposureProgram = 34850,
SpectralSensitivity = 34852,
ISOSpeedRatings = 34855,
OECF = 34856,
SensitivityType = 34864,
StandardOutputSensitivity = 34865,
RecommendedExposureIndex = 34866,
ISOSpeed = 34867,
ISOSpeedLatitudeyyy = 34868,
ISOSpeedLatitudezzz = 34869,
ExifVersion = 36864,
DateTimeOriginal = 36867,
DateTimeDigitized = 36868,
ComponentsConfiguration = 37121,
CompressedBitsPerPixel = 37122,
ShutterSpeedValue = 37377,
ApertureValue = 37378,
BrightnessValue = 37379,
ExposureBiasValue = 37380,
MaxApertureValue = 37381,
SubjectDistance = 37382,
MeteringMode = 37383,
LightSource = 37384,
Flash = 37385,
FocalLength = 37386,
SubjectArea = 37396,
MakerNote = 37500,
UserComment = 37510,
SubSecTime = 37520,
SubSecTimeOriginal = 37521,
SubSecTimeDigitized = 37522,
FlashpixVersion = 40960,
ColorSpace = 40961,
PixelXDimension = 40962,
PixelYDimension = 40963,
RelatedSoundFile = 40964,
InteroperabilityTag = 40965,
FlashEnergy = 41483,
SpatialFrequencyResponse = 41484,
FocalPlaneXResolution = 41486,
FocalPlaneYResolution = 41487,
FocalPlaneResolutionUnit = 41488,
SubjectLocation = 41492,
ExposureIndex = 41493,
SensingMethod = 41495,
FileSource = 41728,
SceneType = 41729,
CFAPattern = 41730,
CustomRendered = 41985,
ExposureMode = 41986,
WhiteBalance = 41987,
DigitalZoomRatio = 41988,
FocalLengthIn35mmFilm = 41989,
SceneCaptureType = 41990,
GainControl = 41991,
Contrast = 41992,
Saturation = 41993,
Sharpness = 41994,
DeviceSettingDescription = 41995,
SubjectDistanceRange = 41996,
ImageUniqueID = 42016,
CameraOwnerName = 42032,
BodySerialNumber = 42033,
LensSpecification = 42034,
LensMake = 42035,
LensModel = 42036,
LensSerialNumber = 42037,
Gamma = 42240,
};

export const GPSIFD = {
GPSVersionID = 0,
GPSLatitudeRef = 1,
GPSLatitude = 2,
GPSLongitudeRef = 3,
GPSLongitude = 4,
GPSAltitudeRef = 5,
GPSAltitude = 6,
GPSTimeStamp = 7,
GPSSatellites = 8,
GPSStatus = 9,
GPSMeasureMode = 10,
GPSDOP = 11,
GPSSpeedRef = 12,
GPSSpeed = 13,
GPSTrackRef = 14,
GPSTrack = 15,
GPSImgDirectionRef = 16,
GPSImgDirection = 17,
GPSMapDatum = 18,
GPSDestLatitudeRef = 19,
GPSDestLatitude = 20,
GPSDestLongitudeRef = 21,
GPSDestLongitude = 22,
GPSDestBearingRef = 23,
GPSDestBearing = 24,
GPSDestDistanceRef = 25,
GPSDestDistance = 26,
GPSProcessingMethod = 27,
GPSAreaInformation = 28,
GPSDateStamp = 29,
GPSDifferential = 30,
GPSHPositioningError = 31,
};

export interface IPiexifGPSHelper {
dmsRationalToDeg(dmsArray: number[][], ref: "S" | "W"): number;
degToDmsRational(degFloat: number): number[][];
}

export type PiexifObject = {
GPS: {[x: number]: any};
"0th": {[x: number]: number};
};

export interface IPiexif {
GPSHelper: IPiexifGPSHelper;
GPSIFD: typeof GPSIFD;
ImageIFD: typeof ImageIFD;
load(binaryStringData: string): PiexifObject;
dump(exifObject: PiexifObject): any[];
insert(exifBytes:any[], binaryStringData: string): string;
}
const piexif: IPiexif;
export default piexif;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestBed, inject } from "@angular/core/testing";
import piexif, { type PiexifObject } from "piexifjs";
import {dump, insert, TagValues, type IExif} from "piexif-ts";

import { ImageResizeService } from "./image-resize.service";

Expand All @@ -24,14 +24,14 @@ describe("ImageResizeService", () => {
it("Should fial to convert the image without location data", inject([ImageResizeService], async (service: ImageResizeService) => {
const exifData = {
GPS: {
[piexif.GPSIFD.GPSLatitude]: [[2, 1], [0, 1], [0, 1]],
[piexif.GPSIFD.GPSLongitude]: [[3, 1], [0, 1], [0, 1]],
[piexif.GPSIFD.GPSLatitudeRef]: "S",
[piexif.GPSIFD.GPSLongitudeRef]: "W",
[TagValues.GPSIFD.GPSLatitude]: [[2, 1], [0, 1], [0, 1]],
[TagValues.GPSIFD.GPSLongitude]: [[3, 1], [0, 1], [0, 1]],
[TagValues.GPSIFD.GPSLatitudeRef]: "S",
[TagValues.GPSIFD.GPSLongitudeRef]: "W",
}
} as PiexifObject;
const exifbytes = piexif.dump(exifData);
const dataUrl = piexif.insert(exifbytes, "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/CABEIAAEAAQMBIgACEQEDEQH/xAAUAAEAAAAAAAAAAAAAAAAAAAAK/9oACAEBAAAAAH8f/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAhAAAAB//8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAxAAAAB//8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQABPwB//8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAgEBPwB//8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAwEBPwB//9k=");
} as IExif;
const exifbytes = dump(exifData);
const dataUrl = insert(exifbytes, "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/CABEIAAEAAQMBIgACEQEDEQH/xAAUAAEAAAAAAAAAAAAAAAAAAAAK/9oACAEBAAAAAH8f/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAhAAAAB//8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAxAAAAB//8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQABPwB//8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAgEBPwB//8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAwEBPwB//9k=");
const res = await fetch(dataUrl);
const blob = await res.blob();
const dataContainer = await service.resizeImageAndConvert(blob as File);
Expand Down
Loading

0 comments on commit e5839fa

Please sign in to comment.