window.ENTITIES={'/api/snippets/bash/bash%20-%20check%20if%20file%20is%20png%20file%20using%20magic%20numbers':[{"result":true,"message":null,"batch":{"type":"bash","name":"bash - check if file is png file using magic numbers","items":[{"id":"pB6Lmp","type":"bash","name":"Bash - check if file is PNG file using magic numbers","content":"[ \"$(xxd -s 0 -l 4 -p \"/path/to/image.png\")\" = \"89504e47\" ] && echo \"image.png is PNG file\" || echo \"image.png is not PNG file\"","source":"https://dirask.com/posts/Bash-detect-PNG-JPG-GIF-file-using-file-bytes-magic-numbers-in-file-j4Z2xD","author":{"id":"b0ZP9a","name":"Khloe-Kaiser","avatar":"1629142895675__b0ZP9a__w40px_h40px.jpg","points":578,"role":"BASIC"},"creationTime":1645552806000,"updateTime":1692827718000,"removalTime":null},{"id":"DWam4j","type":"bash","name":"Bash - check if file is PNG file using magic numbers","content":"if [ \"$(xxd -s 0 -l 4 -p \"/path/to/image.png\")\" = \"89504e47\" ]\nthen\n\techo \"image.png is PNG file\"\nelse\n\techo \"image.png is not PNG file\"\nfi","source":"https://dirask.com/posts/Bash-detect-PNG-JPG-GIF-file-using-file-bytes-magic-numbers-in-file-j4Z2xD","author":{"id":"dDYwEo","name":"Pearl-Hurley","avatar":"1629133461670__dDYwEo__w40px_h40px.jpg","points":559,"role":"BASIC"},"creationTime":1645552837000,"updateTime":1692827727000,"removalTime":null},{"id":"p2Aw0D","type":"bash","name":"Bash - check if file is PNG file using magic numbers","content":"function is_png() # args: file_path\n{\n\t# . P N G (as chars)\n\t# 89504e47 (in hex)\n\t[ \"$(xxd -s 0 -l 4 -p \"$1\")\" = \"89504e47\" ] && return 0 || return 1\n}\n\n\n# Usage example:\n\nis_png \"/path/to/image.png\" && echo \"image.png is PNG file\" || echo \"image.png is not PNG file\"\n\n# or:\n\nif is_png \"/path/to/image.png\"\nthen\n echo \"image.png is PNG file\"\nelse\n echo \"image.png is not PNG file\"\nif","source":"https://dirask.com/posts/Bash-detect-PNG-JPG-GIF-file-using-file-bytes-magic-numbers-in-file-j4Z2xD","author":{"id":"b0ZP9a","name":"Khloe-Kaiser","avatar":"1629142895675__b0ZP9a__w40px_h40px.jpg","points":578,"role":"BASIC"},"creationTime":1645552979000,"updateTime":1692827748000,"removalTime":null}]}}]};