jpg images without extension aren't displayed - kivy

from kivy.uix.image import Image
self.img = Image(source="image") # This works when image is an PNG image
self.img = Image(source="image.jpg") # This works when image.jpg is a JPG image
self.img = Image(source="image") # This doesn't work when image is a JPG image
I need to specify images without extention for the app to be generic (working with more image types). Can I achieve it somehow?

Kivy is using "imghdr" to determine the image type here, and as a fallback it uses the file extension here.
That explains why the image loads fine when it has a file extension, even though "imghdr" can't find the file type in the file's content.
I tested on a list of JPEG files, and each time "imghdr" was able to detect the file type each time. That is done here im imghdr. Notably, "imghdr" does not consider the file extension.
$ python
>>> import os, imghdr
... for f in os.listdir('.'):
... print('%s -- %s' % (f, imghdr.what(f)))
Maybe the JPEG file is missing the "JFIF" or "Exif" string that imghdr is looking for? You could use hexedit to see if one of those string is present at Byte 6 of the image file.

Related

How to convert Unit8List to Files in flutter

I have used opencv to enhance the image in flutter which returns a Unit8List as a dynamic result i have used to display the image.
Image newImage = Image.memory(res);
How to convert that image it to file, or how to write Unit8List as a file. I have tried this but its printing ���� as the file path
File imageNeww = File.fromRawPath(res);
print(imageNeww.path);
Use the file class
File f = File('desired/path/to/file.png');
await f.writeAsBytes(bytes);
here bytes are your Uint8List

Reading Image file in Opencv without ext

I am trying to download an image from URL, but it's difficult to get the complete file name and extension.
Currently, I save the downloaded image with any name and without an extension.
with open(path, "wb") as f:
f.write(request.content)
I then use opencv to read this image which has no extension and it works. How is this possible?
opencv tries magic numbers / signatures for known image formats:
https://en.wikipedia.org/wiki/Magic_number_(programming)
Implementation details:
https://github.com/opencv/opencv/blob/666be238d84c339993bf18c0798d27afd420d6be/modules/imgcodecs/src/loadsave.cpp#L209

Extract/Convert an (multi-file)image that converted

I have a file made with a program , an image sticker maker .
I know this program saves it's images(probably an image, a bg and a mask) into single file with extension ".adf" .
I couldn't convert the output file with image magick cause of below error :
convert: no decode delegate for this image format `output.adf' # error/constitute.c/ReadImage/532.
I don't know how this Image converted with Image magick .
it's my -list configure result :
Path: [built-in]
Name Value
-------------------------------------------------------------------------------
NAME ImageMagick
Path: configure.xml
Name Value
-------------------------------------------------------------------------------
CC vs10
COPYRIGHT Copyright (C) 1999-2011 ImageMagick Studio LLC
DELEGATES bzlib freetype jpeg jp2 lcms png tiff x11 xml wmf zlib
FEATURES OpenMP
HOST Windows
LIB_VERSION 0x671
LIB_VERSION_NUMBER 6,7,1,0
NAME ImageMagick
RELEASE_DATE 2011-07-15
VERSION 6.7.1
WEBSITE http:// www.image magick.org
I attached the file :
src.adf
* EDIT *
if I run file command on src.adf it tells :
root#MexHex-PC:# file -vv src.adf
file-5.25
magic file from /etc/magic:/usr/share/misc/magic
What's missed !?
Thanks
This src.adf looks like a very minimal & flat data file. I know nothing about Dalahoo3D and/or ArcGis products, but we can quickly extract the embedded images with python.
import struct
with open('src.adf', 'rb') as f:
# Calculate file size.
f.seek(0, 2)
total_bytes = f.tell()
# Rewind to beging.
f.seek(0)
file_cursor = f.tell()
image_cursor = 0
while file_cursor < total_bytes:
# Can for start of JPEG.
if f.read(1) == b"\xFF":
if f.read(3) == b"\xD8\xFF\xE0":
print("JPEG FOUND!")
# Backup and find the size of the image
f.seek(-8, 1)
payload_size = struct.unpack('<I', f.read(4))[0]
# Write image to disk
d_filename = 'image{0}.jpeg'.format(image_cursor)
with open(d_filename, 'wb') as d:
d.write(f.read(payload_size))
image_cursor += 1
else:
f.seek(-3, 1) # Back cursor up, and try again.
file_cursor = f.tell()
Which dumps the following three images...
I'm sure this file was made with Imagemagick. I had already seen that one would convert the file to tiff image. He told me to do this with Imagemagick but did not explain the method.
I'm guessing this is just a matter of miscommunication. It's true that ImageMagick commonly handles JPEG / TIFF formats, but not geographic information systems and/or 3D modeling. That's usually extended by a vendor -- like ArcGIS. I would bet that ImageMagick is present in the workflow of generating TIFF files, but .ADF wouldn't be supported by ImageMagick until someone writes a delegate coder.
Update
From this question, it looks like you'll need to extend ImageMagick delegates to call GDAL utilities. You'll need to update the delegates.xml file to call the correct utility.

how can I load images in base64 string by url-loader in typescript + react (rails5 + webpacker)

example repo https://github.com/github0013/typescript_react
I need to load images in base64 string embeded into tag, but importing image files will raise this error.
TS2307: Cannot find module './Octocat.jpg'.
https://github.com/github0013/typescript_react/commit/6670f3ca74404007ad1ed6e4ab0d111f547ee75d
I am still new to typescript, webpack and react, and I am sure I am confused typescript's import and webpack's.
How do I enable url-loader for images? and is this even valid?
https://github.com/github0013/typescript_react/blob/master/config/webpack/environment.js
--
I did try require but it will just return image's path instead of base64 stirng.
// global.d.ts
declare function require(string): string;
solved..
webpacker 3.0.2 already had loaders for image files
https://github.com/rails/webpacker/tree/v3.0.2/package/loaders
https://github.com/rails/webpacker/blob/v3.0.2/package/loaders/file.js
environment.loaders, in rails' config/webpack/environment.js, is just a map, and jpeg png gif are in file loader.
https://github.com/github0013/typescript_react/commit/dc97c3aa9f17bc4f3b0210a426aac27092c5ae7f#diff-41713e6b116dc5cc2bbea556a85db322R3
so overriding file loader's test, then add own image loader will use url-loader for jpeg png gif
https://github.com/github0013/typescript_react/commit/dc97c3aa9f17bc4f3b0210a426aac27092c5ae7f
after adding the loader, regular image require in typescript will return base64 string.

Image class cant read target file

I am trying to read image deep in TEMP folder with Image.read method in order to convert it.
I've seen example like this
I've tried this
InitializeMagick("C:\\Users\\GrayMP\\AppData\\Local\\Temp\\ImageMagick\\Images\\");
Image image;
image.read("result-0.bmp");
and this
InitializeMagick("");
Image image;
image.read("C:\\Users\\GrayMP\\AppData\\Local\\Temp\\ImageMagick\\Images\\result-0.bmp");
, but I catch next exception.what():
app.exe: unable to open image `↑Ё)': Invalid argument # error/blob.c/Op
enBlob/2674
Convertion via ImageMagic works fine, I can do all what I want, but, lib integration doesn't work.
I can't get what I am doing wrong

Resources