Re: repairing jpegs
Posted: 2010-03-03T12:05:20-07:00
try searching google for "unix command line jpg reader" and see if you find anything useful
Use https://github.com/ImageMagick/ImageMagick/discussions instead.
https://download.imagemagick.org/discourse-server/
https://download.imagemagick.org/discourse-server/viewtopic.php?t=15566
i did. i tried about 3 - 4. nothing really useful. my guess is that all the open source programs that use libjpeg (and probably most of them, if not all of them, do) will have the same behavior. so unless some of those are using some other/proprietary libraries - like adobe and that converter do - then it doesn't matter much which one you use...fmw42 wrote:try searching google for "unix command line jpg reader" and see if you find anything useful
that is my next option. will eventually look into that. c is not the problem. the problem is i do not know much about jpeg headers...snibgo wrote:Have you looked at the first 4 (or whatever) magic bytes? Maybe that's all that is wrong. If so, a simple C program could fix it.
it seems imgfoo contains 21 spurious bytes at the start. These can be stripped by a simple C program (or perhaps some shell tool):<magic name="JPEG" offset="0" target="\377\330\377"/>
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
int main (int argc, char *argv [])
{
// Strip the first 21 bytes
FILE * fhin = fopen ("imgfoo.jpg", "rb");
FILE * fhout = fopen ("imgfoofixed.jpg", "wb");
char c;
int i;
for (i = 0; i < 21; i++) {
fread (&c, 1, 1, fhin);
}
while (fread (&c, 1, 1, fhin)) {
fwrite (&c, 1, 1, fhout);
}
fclose (fhout);
fclose (fhin);
return (0);
}
snibgo... i love you man. thanks.... i had a similar script. i just didn't know how many chars to jump... thanks. appreciated.snibgo wrote:imgfoofixed.jpg is now readable by IM and Gimp.
one question. how did you know that they are 21? can you explain please...snibgo wrote: it seems imgfoo contains 21 spurious bytes at the start. These can be stripped by a simple C program (or perhaps some shell tool).