I have uploaded a static image (e.g., at location: /images/no-image.jpg) as part of my code that gets used as the default image when there is no specific image available (basically of the type: "no image for this item")
Just realized that this image may have to be served at more than one size (I have uploaded -- and want to upload -- just one size).
How do I resize this image using Google's Images Service?
If I use the example shown at https://developers.google.com/appengine/docs/java/images/#Java_Transforming_images_in_Java , that means having to read the file, apply the transform, then write a servlet to serve up the file... which seems like a lot of work. Is there an easier way?
Will it be easier to just upload the image to the BlobStore :-)?
You can add the following lines to your CSS file:
.placeholder {
background-image:url('../images/bg.png');
background-repeat:no-repeat;
background-size:contain;
background-position:center;
}
Now, when you don't have a specific image to serve, simply add "placeholder" class to your container element.
Remember to make this image cacheable.
I strongly recommend using the getServingUrl function for serving and resizing images for two reasons:
simpler to use. to resize, you just append parameters to the image url
It will significantly reduce the load off your instances, since the images are served without a servlet, but with google magic
Related
I have an Android app that generates documents with each client's info based in a template, and that the client can sign. The signature is then jointed into the document, and the whole doc is converted to image and uploaded to a server.
Despite being converted to image, the objective is to be as similar as possible to the A4 format.
For this I use WebView, and then I convert it to Bitmap based on the width and height of an ScrollView.
For the signature I use Canvas.
But I'm not sure this approach is the best, as it is very difficult to simulate an A4 document. Depending on the device, the dimensions of the doc are not proportional and to be I would have to be adjusting based on each device display size. Because of that, this component of the app is not available in some devices, purposefully. But now we want to make it available to every device.
What approach do you recommend? Is there some way of develop one doc fits all with correct proportions and similar aspect?
Thanks in advance.
Print to a PDF file. You can use Flying Saucer for that, or similar libraries.
PDF is famous for sticking to definitions and is especially fitted to the needs of proper scaling and displaying.
You could even get away from the doc template and only use (X)HTML to design and fill the page.
Simply fill in some HTML, link an image (<img src='rel.jpg'>), send all that to FlyingSaucer, and you're done.
My goal is it, to make an API-endpoint, where people can provide a String, that will then be added to a randomly selected gif, which will then be returned.
The text will be provided through a link (query param).
Someone recommended me to look at Convert each animated GIF frame to a separate BufferedImage but I'm not completely sure, if the provided solutions would work, for what I want to achieve.
I already did some endpoints, where I create images depending on certain values, which are returned as bytes[] in a getOutputStream().write(), but those are (obviously) only png-images.
Other things to note are, that I store the gifs, which should be edited, locally on the server and that I use sparkjava, to listen for get actions on the endpoints.
Is the recommended answer in the above question a good solution, or is there a better one?
I have an image on top of which I need to add different text based on url parameter. I'm planning to do this with Graphics2D/BufferedImage.
The question is, do I have to save image to disk in order to show it in JSP to the user? The purpose of the image is only be displayed and I'd rather not to save thousands of the images that will be generated...
Thanks!
You do not have to save the image to disk. You can use a bare-bones vanilla servlet to generate the BufferedImage, and then use ImageIO.write() to write that image to the response.getOutputStream(). Just make sure you set the headers to the correct content-type. Then, in the HTML generated by the JSP, just use the URL of the servlet as the src for the img tag.
You can base64 encode the image and chuck it onto the page. Browsers won't cache it, though.
Embedding Base64 Images
https://en.wikipedia.org/wiki/Data_URI_scheme#Web_browser_support
I'm building a very basic gallery on android, it shows the last image on the camera folder and the user can slide left to see the previous one.
I finished an implementation using a viewpager, and a pagerAdapter using sampleSize to scale images. My problem is that the implementation is nowhere as efficient as the default gallery app, every time you slide an image you have to wait around 200ms for the next one to load. So basically my idea on how to implement it is not working out.
How can I do this efficiently, and if possible with an implementation that allows zooming in and out later on?
This looks promising but I don't know how to implement it with files instead of drawables
http://www.androidviews.net/2012/11/photoview/
EDIT:
I've managed to improve speed a bit using photoview (a hacked viewpager), however it takes too much to convert the filepaths to bitmaps or drawables.
I have tried these two methods suggested by dilix and iDroid Explorer:
// Method A
Drawable d = Drawable.createFromPath(imagePath);
imageView.setImageDrawable(d);
// Method B
Bitmap myBitmap = BitmapFactory.decodeFile(imagePath);
imageView.setImageBitmap(myBitmap);
But both produce error Bitmap too large to be uploaded into a texture. I need to get the image to the imageView as fast as possible and somehow bypass this error and maybe I'll get a decent speed. Right now I'm scaling the images and converting them to a drawable but it's not very efficient.
Check this awesome website : http://www.androidviews.net/
and maybe this is what you want: http://www.androidviews.net/2012/11/photoview/
It has page scroll, zooming and panning as you need
I have used it in my project with some modifications and lazy image loading. It is working exactly as you need.
See the official documentation for a great example that will walk you through using bitmaps with a viewpager efficiently. You should use a cache of the images that have already been loaded, and the images should be loaded outside of the UI thread. You also want to scale the image to the minimum size needed for your display (usually powers of two - note that the image won't always scale to what you ask it to!)
ViewPager also loads images in the background to prepare for the next slide, which is set with the setOffScreenPageLimit method (the default is usually good, I think it's 2.)
https://developer.android.com/training/displaying-bitmaps/index.html
I am not sure whether you got correct solution or not. But if you want to continue with your own implementation with your given link then:
http://www.androidviews.net/2012/11/photoview/ //this link is given in your question
And you can see this SO for how to convert file's path in to the drawable. Now, you get drawable of your specified file and implement on the link you have given.
I think that link will works nice.
Feel free to comments.
1)
This looks promising but I don't know how to implement it with files
instead of drawables http://www.androidviews.net/2012/11/photoview/
You have to store not list of drawables in you adapter, but links to files on your sd card and then load it.
2) But i can imagine that file instead of drawables won't be so efficient because to load from files you have to parse it from sd card.
I think you can save time by loading several images in your memory simultaneously (compressed) and when you swype to your othe image you'll already have the image and memory and while swyping you can start loading other image in memory.
When fling over the gallery you may not load images and load it after almost stopping.
It's the main problem: memory consuming vs performance.
UPDATE
I think better than exploring this by yourself will be exploring existing code of google gallery: https://github.com/CyanogenMod/android_packages_apps_Gallery
As i checked - they store cache (almost as i've said about loading multiple bitmaps) and store only resized images - seems to be efficient.
I have done a lot of googling but I have not been able to find a concrete answer.
I am using Spring MVC 3 to save a user image to the database. I am now successfully able to do that. I am saving the image as a BLOB.
I can retrieve the image as a byte[].
Irregardless of file type - jpg, png, gif etc (My image upload is image file type agnostic) I would like to allow jpg and gif and png lets say to render i.e. my display technology should not be hard-coded to display just one type of image, say jpg, it should be able to display all images as they were uploaded in their respective types - that is the requirement.
NOW, I would like to do 2 things
re-size the image if I have to. ie.
200 by 200
render the image in a JSP WITH text.
This is a user profile page so I
need to have both text and image
shown.
How can spring mvc render the image WITH text?
I understand from my research that you can use a BufferedImage type for the jsp? but my problem is that it seems that you can only use that if the content type is strictly image/jpeg, image/gif.
I have come across some links for resizing:
http://forum.springsource.org/archiv...p/t-46021.html
any suggestions welcome if these work BUT ultimately I need to display the image.
Please pass your thoughts along.
Thank you.
Just create a servlet which streams the image from the DB to the outputstream of the response. Then you can just call it the usual HTML way as follows:
<p>
<img src="imageservlet/${bean.imageId}" />
${bean.text}
</p>
As you see, you just display the text next to the image in HTML. You cannot mix them in a single HTTP response anyway. Images counts as separate HTTP requests. For more detail and a kickoff code example of such a servlet, check this answer.
As to resizing, checkout the Java 2D API.