read / write EXIF data, simple, no modifications ???
read / write EXIF data, simple, no modifications ???
Hello,
I have searched the web and the boards to find a simple way to retain EXIF information in an image.
All tools and libs I have found so far har way too big.
I just want to load a jpeg image, and save it again without losing the exif information like:
-loadimage
-get exif block
-do something with the picture
-saveimage
-put exif block
Any ideas?
I have searched the web and the boards to find a simple way to retain EXIF information in an image.
All tools and libs I have found so far har way too big.
I just want to load a jpeg image, and save it again without losing the exif information like:
-loadimage
-get exif block
-do something with the picture
-saveimage
-put exif block
Any ideas?
PB 5.40 LTS, W7,8,10 64bit and Mint x64
Thanks for the answers.
This gets more complicated than expected.
gdi+ is way overpowerd for what I need. Certainly worth looking into it and learn how to use it, but I am more simple minded.
The exif file format link, seemed to be pretty good.
So reading the exif block would not be a problem.
But when you save an image using SaveImage and the UseJPEGImageEncoder you get a JFIF format. I know that EXIF can be in JFIF, but the trick would be now to insert the EXIF data in the JFIF file.
Still trying to make it as simple as possible:
-check for EXIF marker in image
-load the EXIF data block to memory
-load the image using loadimage
-do whatever with the image
-save the image using saveimage
-insert the EXIF block
This gets more complicated than expected.
gdi+ is way overpowerd for what I need. Certainly worth looking into it and learn how to use it, but I am more simple minded.
The exif file format link, seemed to be pretty good.
So reading the exif block would not be a problem.
But when you save an image using SaveImage and the UseJPEGImageEncoder you get a JFIF format. I know that EXIF can be in JFIF, but the trick would be now to insert the EXIF data in the JFIF file.
Still trying to make it as simple as possible:
-check for EXIF marker in image
-load the EXIF data block to memory
-load the image using loadimage
-do whatever with the image
-save the image using saveimage
-insert the EXIF block
PB 5.40 LTS, W7,8,10 64bit and Mint x64
Hey, I got a simple code working.
It consists of 3 blocks.
1. I open a file taken from my camera and read out the EXIF data block.
2. I open a file that has been created from the same image using the PB functions loadimage and saveimage and the JPEGencoder. There I read the entire file.
3. I create a new file and merge der EXIF data with the rest of the file.
Not sure if that is 100% correct, but all my graphic tool still can read the created file and the EXIf info is valid.
edit: updated code for JFIF
It consists of 3 blocks.
1. I open a file taken from my camera and read out the EXIF data block.
2. I open a file that has been created from the same image using the PB functions loadimage and saveimage and the JPEGencoder. There I read the entire file.
3. I create a new file and merge der EXIF data with the rest of the file.
Not sure if that is 100% correct, but all my graphic tool still can read the created file and the EXIf info is valid.
Code: Select all
#file=1
file$="D:\oppi\PB4\stempel\dscf0452_jfif.JPG"
If ReadFile(#file, file$)
length = Lof(#file)
If (ReadByte(#file)&$FF)*256+(ReadByte(#file)&$FF)=$FFD8 ;SOU
Debug "JPG"
APP=(ReadByte(#file)&$FF)*256+(ReadByte(#file)&$FF)
If APP=$FFE1 ;APP1
Debug "EXIF"
ssss=(ReadByte(#file)&$FF)*256+(ReadByte(#file)&$FF) ;SSSS
Debug Hex(ssss)
FileSeek(#file,4)
*memEXIF = AllocateMemory(ssss)
If *memEXIF
rrrr=ReadData(#file,*memEXIF,ssss)
Debug Hex(rrrr)
EndIf
ElseIf APP=$FFE0 ;APP0
Debug "JFIF"
FileSeek(#file,20)
If (ReadByte(#file)&$FF)*256+(ReadByte(#file)&$FF)=$FFE1 ;APP1
Debug "EXIF in JFIF"
ssss=(ReadByte(#file)&$FF)*256+(ReadByte(#file)&$FF) ;SSSS
Debug Hex(ssss)
FileSeek(#file,22)
*memEXIF = AllocateMemory(ssss)
If *memEXIF
rrrr=ReadData(#file,*memEXIF,ssss)
Debug Hex(rrrr)
EndIf
EndIf
Else
Debug "no EXIF, no JFIF"
EndIf
Else
Debug "no JPG"
EndIf
CloseFile(#file)
EndIf
file$="D:\oppi\PB4\stempel\dscf0452_ost.JPG"
If ReadFile(#file, file$)
If (ReadByte(#file)&$FF)*256+(ReadByte(#file)&$FF)=$FFD8 ;SOU
Debug "JPG"
If (ReadByte(#file)&$FF)*256+(ReadByte(#file)&$FF)=$FFE0 ;APP0
Debug "JFIF"
FileSeek(#file,20)
If (ReadByte(#file)&$FF)*256+(ReadByte(#file)&$FF)=$FFDB ;FFDB
FileSeek(#file,0)
Debug Hex(Lof(#file))
*memOst=AllocateMemory(Lof(#file))
If *memOst
rrrr=ReadData(#file,*memOst,Lof(#file))
Debug Hex(rrrr)
EndIf
EndIf
Else
Debug "no JFIF"
EndIf
Else
Debug "no JPG"
EndIf
CloseFile(#file)
EndIf
file$="D:\oppi\PB4\stempel\dscf0452_ost_exif.JPG"
If CreateFile(#file,file$)
WriteData(#file,*memOst,20)
WriteByte(#file,$FF)
WriteByte(#file,$E1)
WriteData(#file,*memEXIF,ssss)
WriteData(#file,*memOst+20,rrrr-20)
CloseFile(#file)
EndIf
Last edited by wichtel on Wed Aug 13, 2008 2:43 pm, edited 1 time in total.
PB 5.40 LTS, W7,8,10 64bit and Mint x64
@DIGE:
I have updated the code. It is by no means final or perfect, but a simple trick that will probably work for me.
Most pictures right out of a camera are in JPEG-EXIF.
Some pictures are in JPEG-JFIF with EXIF info.
The new code will work with those as well.
I did not care about the byte order yet.
I have updated the code. It is by no means final or perfect, but a simple trick that will probably work for me.
Most pictures right out of a camera are in JPEG-EXIF.
Some pictures are in JPEG-JFIF with EXIF info.
The new code will work with those as well.
I did not care about the byte order yet.
PB 5.40 LTS, W7,8,10 64bit and Mint x64
@Fangbeast:
What do you mean with "can you decode exif"?
If you mean if I have written my own EXIF libary - No.
Way too much work. There are so many different info types in there plus vendor specific data...
I thought about extracting just the most needed values. That woul definitly be doable by having a look at the data format and the description in e.g. WiKi. But not yet...
But I could, and you as well, by using an EXIF library. There are several to be found in the net.
e.g. http://www.gimp.org/~tml/gimp/win32/libexif-0.6.16.zip (from gimp)
What do you mean with "can you decode exif"?
If you mean if I have written my own EXIF libary - No.
Way too much work. There are so many different info types in there plus vendor specific data...
I thought about extracting just the most needed values. That woul definitly be doable by having a look at the data format and the description in e.g. WiKi. But not yet...
But I could, and you as well, by using an EXIF library. There are several to be found in the net.
e.g. http://www.gimp.org/~tml/gimp/win32/libexif-0.6.16.zip (from gimp)
Last edited by wichtel on Mon Mar 09, 2009 8:52 am, edited 1 time in total.
PB 5.40 LTS, W7,8,10 64bit and Mint x64
- Fangbeast
- PureBasic Protozoa
- Posts: 4749
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Hadn't even thought of that, thanks.wichtel wrote:@Fangbeast:
What do you mean with "can you decode exif"?
If you mean if I have written my own EXIF libary - No.
Way too much work. There are so many different info types in there plus vendor specific data...
I thought about extracting just the most needed values. That woul definitly be doable by having a look at the data format and the description in e.g. WiKi. But not yet...
But I could, and you as well, by using an EXIF library. There are several to be found in the net.
Amateur Radio, D-STAR/VK3HAF