i am programming a jquery plugin which loads lots of images.
I would prefer to show the picture first fuzzy and if it's fully loaded, in complete.
Facebook is a good example.
How does this technique work?
This depends on the format that the image is saved in.
JPG images normally load (and hence display) from top to bottom. If however they are stored in progressive (also called interlaced) format then they will load the whole image in a grainy format and gradually increase the quality. Facebook save their images in the progressive format.
There are utilities available for converting from the first format into the second. Here is a link to a well known one (ImageMagick): ImageMagick
You just have two images: one of bad quality, and one of good quality and.
When you want to show image, you first set image.src to bad quality image, and then instantly to good image path (setTimeout with 0 delay will work too).
It works, because browser doesn't replace image in img tag until it's fully loaded. Image with bad quality will loaded much faster than good image, so user will first see fuzzy image and fully loaded image when it's loaded.
Example
img.src = 'path/to/fuzzyImage.jpg';
setTimeout(function() {
img.src = 'path/to/fullImage.jpg';
}, 0);
The usual approach is to set width and height on a thumbnail version of the image to full size of the big image, and replace the thumbnail with full image when the large one is loaded. When you set the full size on the thumbnail image, it becomes 'fuzzy' becuase it's interpolated to a larger size by the browser.
Related
On the main page it's showing blurry image in futured posts.
website link:- iguidu.blogspot.com
I tried different methods but it is not working. can anyone?
related script:-
Original image is only 72px and you're rendering into a large box, You're basically using thumbnails in the place of featured image, this is the reason it's blurry. try using larger images, ideally to the expected rending size, in your case 490 x 305px
In your case, this seens to occur because of the images size. If you open each image in a new tab you will see that teir original size are 72x72 although the display size (the size that us, clients, are seeing) is 490x305.
How to correct this ? The ideal is to get a bigger image, and also an optimized one. The most optimezed format for web is .webp. Check on THIS link what is this.
Another important thing when comes to resize image is to keep the aspect ratio, but I don't think you are experiencing any issue with that, although I will let a LINK talking about it.
I came across the problem of image loading in website.
It's need to load 3 high resolution images in home page, and when open, it's showing website other contents first and load this images which is fine for now.
But it's slightly awkward, and would like to have similar image loading process like Google image search.
When I click image in Google, it shows blurred or pixelate image which seems like low resolution and lower size and loading original image a bit later.
They might use special thing as they are Google, but if someone have done this kinds of things before, I need your help.
Thanks in advance
Sounds like you want what are called "progressive JPEGs", where multiple images of varying quality are saved in one file, and the browser loads the low resolution images quickly to get something in the page, and replaces it with higher resolution images once they've been loaded.
Here's a tutorial on saving JPEGs for the web as progressive in Photoshop
You can use jQuery. The following is a general idea, not an exact code.
For each image use something like:
<div>
<img id="myimg" src="" style="display:none">
<img src="low-res-version link">
</div>
You should also keep a low res image.
Use jQuery to set your images src after the page loades, and use the next() function to remove the low res image.
$(document).on('ready', function() {
$('#myimg').attr('src', 'link to the image').on('load', function() {
$(this).css('display', 'block').next().remove();
}
You can also check this question: Fast Image loading methods, low to high res with multiple backgrounds - javascript solution?
Well, I choose resolutions from the server-side;
loading the low-res immediately in a z-index=0 object,
loading the one or more hi-res objects into negative z-index objects
and then at onload(), choose which object should be on top
I am working on a website that has image blocks, with various sizes (relative width based on the current size of the parent, parent also have a relative size to window). I use jquery load event to rewrite the src attributes of the images based on the image object's dynamic size to ensure pixel perfect view. The problem is that the browser download the full size image, than replace it with a dynamically generated one. This leads to unnecessary loadings and speed loss.
What if I let the src value empty, that add the correct url into it? I would like to stay seo optimized, so an empty src maybe not a good idea. Can I achieve this without double downloading images? Maybe I should use an event before the browser begins the download the src data.
My code:
$('.image').load(function () {
if (!$(this).hasClass('optimized')) {
$(this).attr('src', '/image-perfection.php?image=' + encodeURIComponent($(this).attr('src')) + '&width=' + $(this).width());
$(this).addClass('optimized');
}
});
Create a small thumbnail, and let your images to point to the same thumbnail image.
The advantage of this is that you can specify a 'loading' like image that will be pre-catched by the browser for next requests, and then you can load the images the way you do.
You can also write a proxy script that cut the images in the server for you, if you're working with uploaded images you can cut them once they're uploaded for optimize the process, of course it depends of how your implementation must be.
I have a page where I will be loading a couple of different sizes of the main image; although not all the large images will be loaded at once.
The scenario is this..
I have a slider which contains the thumbs for all the larger images; these all load when the page does.
The default large image loads when the page does, but the other large images only load if the user clicks on the thumbnail for that image and then I replace the src of the large image as so..
function changeMainImage(image) {
// Set big image
var big_image = image + '-big.png'
// Update main image url
jQuery('#main_image').attr('src', big_image);
}
Now because the large images don't load when the page does, this causes a small delay for the large image to show, which is rather undesirable.
Now I'm thinking that I could kill two birds with one stone with just loading the large image and no thumbs and just have the browser scale the large image into a thumbnail; I just kinda cringe at doing it this way as I have always hated sites that use this method for thumbs, but in my case it seems valid as I need to load the large image anyway.
This would allow me to reduce the number of http requests by 1 * amount of pics and also give me instant load of the large images once the thumb is clicked.
My only concerns are trying to figure out how to give the browser the correct dimensions so that the image scales to the correct proportions and also the fact that if the page has say 12 images; this way I am making the user download all 12 large images at once when they make not even be interested in looking at all 12.
Both versions have pros & cons - any advice what to do here?
The method you currently have is what I prefer to do. Load what is visible.
Now, to make the user experience better, many sites use a couple techniques. The first would be to pre-load the next image or two. If you have a slideshow-like display and have a good idea of what order the images will be displayed in, this is good.
The second is to display the thumbnail while the large version downloads. If your thumbnails are of a decent size, this lets the user get visual feedback that their click worked, and on decent connections the image will be downloaded soon after.
Finally, I recommend using progressive JPEG (if your images are photos) so that they are enhanced as they load.
For your data on sizes (and any other metadata), keep that in a JavaScript array of objects, or wherever else you store your image data. You can easily use JSON for transit from the server.
Lots of cameras are now putting thumbnails into their JPEGs and RAWs images.
I'd like to be able to autoload some images and then display only the thumbnail, or better yet autoload only the thumbnail portion for speed.
Is there a way to do this in Javascript?
Thanks.
You've said you want to do this in the browser, so when you say:
...or better yet autoload only the thumbnail portion for speed.
You're not going to get a speed benefit from doing this client-side, because the entire image must first be downloaded before you can make a thumbnail for it.
You can create thumbnails for retrieved images, just by creating an img element and settings its width and height to something smaller; the default thing browsers will do is scale the image down (not necessarily in a pretty way).
Example:
var img = document.createElement('img');
img.src = "your image url here";
img.style.width = "32px"; // Change as appropriate
img.style.height = "32px"; // Change as appropriate
document.body.appendChild(img); // Or append to some other container element
Live copy
There I've assumed it's apprpropriate to force the image to be a certain width and height (frequently with thumbnails, it's useful if they're all the same size, although the above will mess with aspect ratios).
If you want to resize by a percentage (say, 25%), you can do that but it's more complicated: You have to create the image, load it off-screen (there are various ways to do this), wait for the load to complete, and then do the calculation.
If you're running a server, you're probably better off finding something that can pre-process the images and create thumbnails for you. ImageMagick, for instance, can help with that server-side.