| 429 | |
| 430 | |
| 431 | const char* NoteFormatter::findImageFormat(QString file) { |
| 432 | QByteArray b; |
| 433 | QFile f(file); |
| 434 | f.open(QFile::ReadOnly); |
| 435 | b = f.read(10); |
| 436 | f.close(); |
| 437 | |
| 438 | // Try to determine the type of image from the "magic bytes" |
| 439 | if (b.startsWith("\xFF\xD8\xFF")) |
| 440 | return "JPG"; |
| 441 | if (b.startsWith("\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")) |
| 442 | return "PNG"; |
| 443 | if (b.startsWith("GIF87a")) |
| 444 | return "GIF"; |
| 445 | if (b.startsWith("GIF89a")) |
| 446 | return "GIF"; |
| 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | |
| 451 |