I am coming from an asp.net background where if you want to display a photo gallery you have to have two files for each photo i.e. the original and a separate thumbnail file.
If I was to create a Win8App gallery that has say 100 photos per view. Would it be okay performance wise to simply change the size of the photo... i.e. only have the 1 file. (These are loaded from the file system).
I know it may depend on certain conditions but generally what is the best way to do it?
Depends on the file size, and where you get them from. If the files are on the system you could use StorageFile.GetThumbnailAsync. Otherwise, if the files are large and you are getting them from somewhere else (a service) you could load them only as they scroll into view for the user. Make sure to dispose objects as you are not using them as bitmaps are notorious for eating up memory resources.
100 images doesn't sound like a lot for me, but it's better to have numbers to back that statement up with as I have no idea how large the files are.
Here are some general guidelines for thumbnails from MSDN
I would try different ways to deal with it and use the performance tools to see what the end result is. Maybe you could group the images and have the user view one group at the time, maybe use placeholder images, or maybe the files aren't that big and its no problem at all to simply resize depending on view.
For lazy loading (recommended with many items) use data virtualization by implementing the ISupportIncrementalLoading You can find more information about that on MSDN.
Related
We are building an sitecore app that is largely image base content.
Currently we are seeing performance slowdown on pages with lots of images on iOS.
Most of our images are in sprites, but user images are currently loaded one by one.
Has anyone come up with a way to generate sprites from images uploaded to sitecore ?
I found this blog post about how to handle sprites in Sitecore with svg.
I hope it will help you to resolve your issues.
I've done some concept work on this topic before, but haven't yet found the time to do a real implementation. But I'll try to share a few of my thoughts on how to do this.
First you have to identify the images that should be in the sprite. This can be done at the page request by traversing the item fields and potentially the related items, or if you have any other logic where you can get this. If the list is static, it would be even better to determine this at publish time. Essentially you need each image guid, width and height. You'll also need to look into what image sizing rules you have. The images in the sprite needs to have a similar width or height in common. Otherwise it would be hard to group them without having large blank areas.
When you have the set of images, you can get the MediaItems and find the information needed to build the html code for the sprite. Essentially the X and Y coordinates where each image will be located in the sprite, so that you can render the html correctly. This would also result in an object that contains all the information to create the sprite. This object can be assigned a guid, that you can use in the image url to request the sprite.
Note that if you're on a multi-server environment, you'll have to look deper into what strategy you want to use for persisting the data about the sprites. You could for example store it in Mongo if you have it, or use a database that is accessible from all content deliver servers. In a multi-server environment the html-request may be on one server and the image sprite request on another server, so it must be possible to retrieve or build the sprite from the information in the image url alone. (This would be best practise in a single server env as well, but it becomes a lot simpler)
Then you'd create an image request handler that gets the sprite object guid, and from the persisted sprite object, it'll get the media items, optionally perform resizing etc, and render those onto a Bitmap. The Bitmap can then be saved as jpg/png and cached on disk (or other suitable service) and returned to the client.
There are of course a lot of different ways to do each part of this and most of it would depend on what data you can put into your sprites (data driven, hand-picked by users on the current item or related items, usage of personalization etc etc), if you can perform pre-calculations of the sprite object and generate the sprite at publish time or if it has to be done render time, what your hosting environment looks like etc etc.
Hope this helps
We are developping an e-commerce application and I have a bit of a problem.
Right now we have 2 MVC applications:
A main MVC application which role is to manage the inventory and set items to sale;
Another MVC application which will serve as a the e-commerce on which the items set to sale by the main application will be displayed.
My main problem is that these two shares a same library of image, and this library is huge (about 60 000 images and counting). Up to now to allow a fast process each project has a physical copy of each images "~/Images/BankImages/FullImage/theFirstImage.jpeg", and so on, but you can guess that this is a pretty huge library that takes a lot of room.
I'm looking for options on how I could develop something that would return an image in whichever C# format. I was thinking about a web service, I suppose, which task would be to return these images upon being called, but I don't know how I can do it (newb here) and I think I may lose a bit of speed because a call to the web service may not return immediately the needed image, and I may have to retrieve a few hundred of these images at the same time.
So I'm looking for suggestions. What would be the best way to solve my main problem and avoid (if possible) having to copy each time the whole image library?
Thanks a lot!
When You say:
My main problem is that these two shares a same library of image
This mean you need a single assets repository, so you need a CDN, same asset, common API
Currently we have a page, where people can amend (crop, resize, etc..) images they have uploaded into the system. Everything works fine, but we have to improve the performance, especially the page load, so I'm looking for some advice.
The problem is that on our page, we have to display around 70-80 images. The source of all the images () are set to point to a Controller method, as we have some special rules in place to build up the full path of the images. (no DB calls are made there)
Obviously, this results in many calls to retrieve the images, which's ok up to a point, but after a while, it just becomes slower and slower.
So the questions is: What would be the best way to go about handling such a scenario?
Would it make any difference if instead of a Controller method we would use an HttpHandler to return the images?
Any input is greatly appreciated.
You can use images lazy loading plugin for jquery.
example: http://www.appelsiini.net/projects/lazyload
can you stitch the images together at the server, transmit them as a single ImageMap, then use CSS sprites (http://css-tricks.com/css-sprites/) on the page to display them?
Looking for information - I am creating a catolog website that includes a list of products. Each product has an image stored stored on the hard drive on the server. If the image does not exist, I want to show a default image. Whats the best way of doing this. I am using C# and considered checking on the server side if the image exists. But as some pages could have 50-60 images this would slow down the page. I use jquery on the client side. Any tips on this?
This is a great question, as the sitation arises in many circumstances. I see several options:
1) check for image availability during rendering of the catalog and use a link to the default image for items that do not have an image,
2) check for image availability in the image controller and return the default image when not available
3) put images inline in the document using data URLs
A major factor here is the possibility of caching.
Option (1) facilitates caching of the default image, but precludes caching of the catalog page. It is better if there are many items without an image, then such items will not even generate a hit to the server Furthermore, if there's a low chance that an image would appear for an item, you could cache the index too (for a reasonably short time).
Option (2) facilitates caching of the index page, but each image will have to send a request to the server. Again, you could use aggressive caching to avoid the same requests the second time the page is rendered.
Option (3) is best if your images are small and if the catalog page is relatively static. Be sure to use caching on the server side though while generating the page to reduce the load on the filesystem/database.
Sounds like this is a web application, so you should look into doing some caching. Even though image file lookups are expensive, once your page gets hit a few times the disk lookups will no longer be necessary.
Or you could store the information about whether a product image exists in your database. Then you prepopulate the database with the information and no disk checks are necessary.
Your best bet is to do this server-side as you suggest. You could do it client-side (attempt to load image, and load a default image if that fails), but this is not really what client-side scripting is designed for. You're making the user do extra HTTP requests, which is slower for the user.
An even better solution, as marcind suggests, is to pre-populate the database with default images. So in your CMS, when you create a new item, it assigns a default image URL to itself. You can then manually change it from there.
How does your jQuery code know the name of the image?
Seeing that your image files are physical files on the server and are accessible from a browser, I'd probably leave that part as is since that implies you don't have to serve the images yourself and IIS can handle that for you as a static file.
So your jQuery code obviously know the name of the image for each product. I assume this name is given to it by some server side process, so that process needs to give it either the name of the image for the product or the default image.
Some part of your code has to go through the process of figuring out if an image exists for the product and react accordingly. If you're using a database for your products that you could have a field in product table that indicates if the product has an image or not.
Basically functionality i need is:
easy integration with ASP.NET application.
user ability to crop image with handle prior to save
image optimization from any image type to jpg (compression levels) during the save
saving images with proper h/w ratios during the save
user ability to rotate the image prior to save
ability to translate application to foreign language as it won't be used on international site
If you know any application which fits my needs even if it costs money, give me a twit...
Our company has implemented a photo cropper in an ASP.Net MVC application using Atalasoft's DotImage. I did not implement this myself, but I currently maintain the whole of that application (and consequently the cropping component).
Based on the way you phrased your question, I feel that I should explicitly point out that Atalasoft's DotImage only provided the functionality to manipulate images. Other answers referenced ImageMagick and GDI+. In the same vein, these libraries also only provide the functionality to manipulate images.
We had to implement the UI and workflow ourselves. This was, while not rocket science, still far from trivial. While we used a pre-built component for fancy, AJAX-y file uploads (for the source photos) - we still had to integrate that into the application and manage persistence of the files and database records associated with them. (Similarly, as a convenience we allow import photo from url - another feature we had to explicitly create)
I would suggest that you will not find any general purpose component to integrate that will give you cropping functionality and a Web UI. I suppose there may be one made by a ASP.Net component vendor, but I am certainly not aware of any off-hand.
The problem tends to involve lots of pieces that span from the client to the server, and consequently I think what you are looking for will involve a fair amount of specific-to-your-application development and integration.
You can try ImageMagick, it supports hundreds of image formats and it comes with a .NET wrapper.
Have found exactly what i was looking for iLoad
Does exactly what i asked and doesn't cost that much compared to other suggested solutions. Haven't tried it yet but demo is impressive.
Have a look at mcImageManager