How to get Image's extension from url in Flutter? - image

I have an url that corresponds to an image.
The url looks like https://myImageUrl (there's no reference to the extension).
I want to show this image but i don't know if it's an svg or a jpg.
Is there a way to get the image's extension from its url? I've tried mime package https://pub.dev/packages/mime but it doesn't work.
I need to know the image's extension because:
if it's a svg I'll use SVG library
if it's a jpg I'll use Image.network('myImageUrl')

Is there a way to get the image's extension from its url
No. If it's not there, it's not there. There is no magic available that would show missing information.
Since you want to load it from assets if it's an svg (which seems weird, but okay), you could just check the given URL against all assets... if it's in their, show it from assets.

Related

using img in html code. But how come the image does not show? but instead a little file shows

I'm using the mimo code app for coding. I saved a picture from google in the folder "Saved Pictures". The file name is "generic background". I did the code <="/Saved Pictures/generic background.jpg">. But the image does not show. Instead what shows is a small file. Don't really know how to get the image to show. I did used img src before =, but I need 10 reputations points to post an image even though I was just trying to show the code.

Liquid Pixels check source image mime type

unfortunately, I cannot tag this post with the correct "technology" because it does not exist and i dont have 1500 reputation to create it.
We are using a cloud service called "Liquid Pixels" to render some stuff on our images.
Lets say we have an image chain that is currently rendering a ribbon on the given JPEG image. This chain is working fine.
Then I adapted the chain to work with animated gif images, therefore I changed the sink format to gif (sink=format[gif]). That was working fine as well.
Now I want to combine the two cases in one chain, because the only difference is the sink command. The plan is to check the MIME type of the source image and then either render a gif or a jpg image.
I rendered the image as xml to view the metadata map.
I thought i can do it like this.
source=url[https://something.com/1x1_sample.gif],name[testImage]
sink=format[gif],if[('testImage.format' eq 'GIF')]
sink=format[jpg],if[('testImage.format' ne 'GIF’)]
But for some reason I cannot access the format attribute. I am used to grab some parameters like “testImage.width” or “testImage.height”, but for some reason i cannot access the format=“GIF” property. I guess that has happens because the width and height are on a different hierarchy level in the metadata map.
I hope you guys can help me.
The image does not actually have a "format" during the render. Only a file has a format. During processing the image is simply on memory as either raster or vector data; it is only when you sink that it becomes a file in whatever format. Also, LiquiFire OS uses the image data to determine the original format when acquiring an image from a source, never the image name itself.
If you need operations in your LiquiFire Image Chain to react to the source image URL, you can test the last part of the image name by applying a regular expression to see if it is either .GIF or .gif. An example of how that can be done:
set=imageURL[https://your.server.com/sample.gif]
source=url[global.imageURL],name[testImage]
regexcase=name[isGif],key[global.imageURL],cases[\.gif$|\.GIF$|\.\w+$],values[yes|yes|no]
sink=format[gif],if[('global.isGif' eq 'yes')]
sink=format[jpg],if[('global.isGif' eq 'no’)]

Why would I need image placeholder service or library?

Yesterday, I saw a tweet saying about holderJS library. When I read the usage, it says it will generate the image placeholder completely on client side. So I am wondering why in the life would I need a placeholder library?
What is the scenario in which rather than placing div of some size I would use image placeholder?
Image placeholders are generally meant for a page that is either in the process of dynamically loading a real image or the page is only partially designed and the placeholder image shows how the design will be laid out and how big the image should be even though the real image is not yet available. In this way, the HTML design can be nearly completed even though the final images are not yet available or done.
Wikipedia uses image placeholders when they know they want a particular image in a page, but are in search of an image they can use with the appropriate license.
Image placeholders are traditionally served up by a service on the web that automatically creates the placeholder images based on query parameters in a URL, but the holder.js library creates placeholder images entirely on the client (so no outside services are needed).
You can certainly achieve the same look as a placeholder with just a div with a background color and perhaps even some text in the div. But, when someone wanted to plug the final images into place, they would have the change the div tags to img tags. When using a placeholder image, all the HTML tags can be final and left as they are, only the .src values need to be plugged in to finish the design. So, placeholder images allow you to have a closer to complete version of the HTML even though the images are not yet done. It's a minor different, but one that is appreciated by some designers.

Thumbnail-like behavior using target attribute of image directive

I use Sphinx to generate some docs. I have a reStructuredText document and I'd like to put an image into it. The case is that the image should be clickable so that after a user clicks the image then they should be shown this image in full size. I use the image directive and its target option like this:
.. image:: /images/some_image.png
:alt: Image descripion
:align: center
:target: `big_some_image`_
.. _big_some_image: /images/some_image.png
The problem is that in the rendered page I get:
<img src="../../../_images/some_image.png">
So there is correct src from the image directive but an incorrect href attribute from the hyperlink.
Questions:
is there any way to generate links in the way that image directive does it? I mean relative to the document.
is there any other (built in) way to have "thumbnail-> click -> big image" behaviour?
Simply use the scale option:
.. image:: large_image.png
:scale: 20%
When the scaled image is clicked on, the full image loads in its own window. So this doesn't increase the image size on the page, but that would be messy anyway.
When you use the image directive from within Sphinx, Sphinx does some special handling to find the image file and copy it into your project (like your _images directory), and then renders the HTML to point to that place.
But the target option just takes a URL as a parameter. It knows nothing about your Sphinx project, or how your images are laid out, and does not attempt to guess.
If you want to have it point to a larger version of the same file, you will likely need to do some manual steps (like maybe copying the file to a specific location), or maybe provide a relative URL to the large file, rather than the absolute URL you have in your example.
If you want to go a completely different way, you could also try overriding and modifying the HTML templates for your project to add some JavaScript to get the click-to-larger-image effect you want.
Looks like there is a Sphinx extension that does this now, and quite nicely at that, sphinxcontrib-fancybox 0.3.2. Install with pip, add it to your extensions in conf.py, and use the fancybox directive:
.. fancybox:: images/image.png
Relative links seem to work. For the Mapserver docs setup, if an image is placed in the images directory, a relative link like in the following code works in my local build. Here is an example using figure (the underscore ("_") before "images" in the target link is necessary):
.. figure:: ../../images/carto-elements.png
:height: 400
:width: 600
:align: center
:target: ../../_images/symcon-overlay.png

Is it possible set the JPEG quality using the get_serving_url() in Google App Engine?

When using get_serving_url(user.photoBlobKey) to return an image URL from the GAE Blobstore, the Google Images API returns a JPEG image with quality = 70 and size = 512px as default.
Is there any way to increase the default JPEG quality returned by get_serving_url()?
There's an undocumented URL parameter l, you can add it to the end of the image URL like so: =l100 (or =s640-l70 if you have another param before it) that should modify the output quality of the JPEG. Seems to be =l1 to =l100.
See also: List of all the App Engine images service get_serving_url() URI options
No there is not.
If you think it's a useful feature you can add an item to the issue tracker, from there the team will assess the demand for implementing it.
you can't control the output quality but by requesting
get_serving_url(user.photoBlobKey, size=0)
you will get the original size of the image up to 1600px height and width.
the returned url will be automatically postfixed with =s0 which you could add also before rendering the image in the template for example.

Resources