in

dashCommerce

An ASP.NET Open Source e-Commerce Application

Thumbnails

Last post 03-24-2008 12:31 PM by Timmey. 25 replies.
Page 1 of 2 (26 items) 1 2 Next >
Sort Posts: Previous Next
  • 02-27-2008 10:06 AM

    Thumbnails

    I am using Dashcommerce for an e-commerce site and need to know how to create good looking thumbnails.

    Any tips on how to do it in DashCommerce?

  • 03-10-2008 11:54 AM In reply to

    Re: Thumbnails

    if your using 3.0 make them 150x150, if you use fireworks , you can batch process sometime betters to reduce size by %

    2nd image on product page works at 300 to 400 wide.

     

  • 03-18-2008 9:13 AM In reply to

    Re: Thumbnails

    You could create an Image Service.

     private Bitmap resize(Stream SourceImage, int MaxWidth, int MaxHeight)
        {
            Bitmap b = null;

            using (Image i = Image.FromStream(SourceImage))
            {
                int _maxWidth = (MaxWidth > 0) ? MaxWidth : i.Width;
                int _maxHeight = (MaxHeight > 0) ? MaxHeight : i.Height;
                double _scaleWidth = (double)_maxWidth / (double)i.Width;
                double _scaleHeight = (double)_maxHeight / (double)i.Height;
                double _scale = (_scaleHeight < _scaleWidth) ? _scaleHeight : _scaleWidth;
                _scale = (_scale > 1) ? 1 : _scale;

                int _newWidth = (int)(_scale * i.Width);
                int _newHeight = (int)(_scale * i.Height);

                b = new Bitmap(_newWidth, _newHeight);

                using (Graphics g = Graphics.FromImage(b))
                {
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.SmoothingMode = SmoothingMode.HighQuality;
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.DrawImage(i, new Rectangle(0, 0, _newWidth, _newHeight));
                    g.Save();
                }
            }
            return b;
        }

    Something like this, get an image, modify it safe it to a stream or return it.

    *Freetime Freestyle DashCommerce development*

    Currently working on:
    ##############################################################
    · TagCloud - patching
    · Headline Generator 50%
    · Navigation XHTML with Images 80%
    · Extended Shopping Cart Widget - 5%
    · XML Sitemap Service Exporting for Google, Froogle what ever. 33%
    - JQuery Implementing for better JLib Support 70%
  • 03-18-2008 9:35 AM In reply to

    Re: Thumbnails

    Thanks! Where do I put this code in ie ProductSummaryDisplay.ascx.cs, and how do I call the function to show the images in ProductSummaryDisplay.ascx?

     

  • 03-18-2008 9:50 AM In reply to

    Re: Thumbnails

    Create a new generic Handler in Visual Studio.

    This is the Code For it:

    <%@ WebHandler Language="C#" Class="ImageService" %>

    using System;
    using System.Web;
    using Commerce.CaptchaImage;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Imaging;
    using System.Net;
    using System.IO;

    namespace SitesBytes.ImageHandler{

    public class ImageService : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            if (context.Request["r"] != null)
                ImageResize(context);
           
        }

        public void ImageResize(HttpContext context )
        {
            Image sourceImage = GetImageFromURL(/*PUT YOUR DOMAIN HERE*/ + context.Request["src"]);
           
            double width = (context.Request["width"] != null) ? Convert.ToInt32(context.Request["width"]) : 100;

            double sizeFactor = width / sourceImage.Width;
            double newHeigth = sizeFactor * sourceImage.Height;
            Bitmap newImage = new Bitmap((int)width, (int)newHeigth);
            using (Graphics g = Graphics.FromImage(newImage))
            {
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.DrawImage(sourceImage, new Rectangle(0, 0, (int)width, (int)newHeigth));
            }
            newImage.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
        private static Image GetImageFromURL(string url)
        {
            HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
            HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
            Stream stream = httpWebReponse.GetResponseStream();
            return Image.FromStream(stream);

        }
       

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
    }

     

    The URL to Call the handler is:

    <img src="~/Imagehandler.ashx?r=~/images/test.jpg&w=200" alt="something" />

    That means the Image is in domain.com/images/test.jpg
    The resized width is 200

    Didnt have the time to test it right now, but it should work.

    Cheers

    Timmey

    *Freetime Freestyle DashCommerce development*

    Currently working on:
    ##############################################################
    · TagCloud - patching
    · Headline Generator 50%
    · Navigation XHTML with Images 80%
    · Extended Shopping Cart Widget - 5%
    · XML Sitemap Service Exporting for Google, Froogle what ever. 33%
    - JQuery Implementing for better JLib Support 70%
  • 03-18-2008 10:03 AM In reply to

    Re: Thumbnails

    Thank you!

    I will test it out, if it works you are my true hero! Big Smile

    I have been struggling with this for nearly 3 months now...

    I´ll let you know!

    Cheers! 

     

     

  • 03-18-2008 10:12 AM In reply to

    Re: Thumbnails

    If you run into any pain let me know.

    Just post the infos you need or the error you get.

    To test the service you can call the url directly like: domain.com/imageservice.ashx?...

    You see the detailed infos there.

    *Freetime Freestyle DashCommerce development*

    Currently working on:
    ##############################################################
    · TagCloud - patching
    · Headline Generator 50%
    · Navigation XHTML with Images 80%
    · Extended Shopping Cart Widget - 5%
    · XML Sitemap Service Exporting for Google, Froogle what ever. 33%
    - JQuery Implementing for better JLib Support 70%
  • 03-18-2008 10:25 AM In reply to

    Re: Thumbnails

    Thank you, I just created the generic handler and get this error message:

    http://www.ergona.se/modules/products/ImageHandler.ashx

  • 03-18-2008 10:33 AM In reply to

    Re: Thumbnails

    Answer

    AH okay just delete this line of code.

    *Freetime Freestyle DashCommerce development*

    Currently working on:
    ##############################################################
    · TagCloud - patching
    · Headline Generator 50%
    · Navigation XHTML with Images 80%
    · Extended Shopping Cart Widget - 5%
    · XML Sitemap Service Exporting for Google, Froogle what ever. 33%
    - JQuery Implementing for better JLib Support 70%
  • 03-18-2008 10:37 AM In reply to

    Re: Thumbnails

    Ok, I deleted the file, now I seemed to have written something wrong where the url is supposed to be, please have a look at the same link.

  • 03-18-2008 10:39 AM In reply to

    Re: Thumbnails

    GetImageFromURL("http://www.ergona.se" + context.Request["src"]);

    The Url has to be like: http://www.ergona.se/modules/products/ImageHandler.ashx?r=1src=images/productimages/test.jpg

     

    *Freetime Freestyle DashCommerce development*

    Currently working on:
    ##############################################################
    · TagCloud - patching
    · Headline Generator 50%
    · Navigation XHTML with Images 80%
    · Extended Shopping Cart Widget - 5%
    · XML Sitemap Service Exporting for Google, Froogle what ever. 33%
    - JQuery Implementing for better JLib Support 70%
  • 03-18-2008 10:45 AM In reply to

    Re: Thumbnails

    Now I get this:

    Server Error in '/' Application.

    Parser Error

    Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

    Parser Error Message: Could not create type 'ImageHandler'.

    Source Error:

    Line 1:  
    Line 2:  
    Line 3:  using System;

    Source File: /modules/products/ImageHandler.ashx    Line: 1


    Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210  

     

  • 03-18-2008 10:46 AM In reply to

    Re: Thumbnails

    <%@ WebHandler Language="C#" Class="ImageHandler" %>

    is missing

    *Freetime Freestyle DashCommerce development*

    Currently working on:
    ##############################################################
    · TagCloud - patching
    · Headline Generator 50%
    · Navigation XHTML with Images 80%
    · Extended Shopping Cart Widget - 5%
    · XML Sitemap Service Exporting for Google, Froogle what ever. 33%
    - JQuery Implementing for better JLib Support 70%
  • 03-18-2008 10:48 AM In reply to

    Re: Thumbnails

    Here is my code:  (I want to retrieve images from a folder with path "images/ProductImages"

     

     

    <%@ WebHandler Language="C#" Class="ImageHandler" %>

    using System;

    using System.Web;

    using System.Collections.Generic;

    using System.Drawing;

    using System.Drawing.Drawing2D;

    using System.Drawing.Imaging;

    using System.Net;

    using System.IO;

    namespace SitesBytes.ImageHandler{

    public class ImageHandler : IHttpHandler

    {

    public void ProcessRequest(HttpContext context)

    {

    if (context.Request["r"] != null)

    ImageResize(context);

     

    }

    public void ImageResize(HttpContext context )

    {

    Image sourceImage = GetImageFromURL("http://www.ergona.se" + context.Request["src"]);

     

    double width = (context.Request["width"] != null) ? Convert.ToInt32(context.Request["width"]) : 100;

    double sizeFactor = width / sourceImage.Width;

    double newHeigth = sizeFactor * sourceImage.Height;

    Bitmap newImage = new Bitmap((int)width, (int)newHeigth);

    using (Graphics g = Graphics.FromImage(newImage))

    {

    g.InterpolationMode =
    InterpolationMode.HighQualityBicubic;g.DrawImage(sourceImage, new Rectangle(0, 0, (int)width, (int)newHeigth));

    }

    newImage.Save(context.Response.OutputStream, System.Drawing.Imaging.
    ImageFormat.Jpeg);

    }

    private static Image GetImageFromURL(string url)

    {

    HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);

    HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();

    Stream stream = httpWebReponse.GetResponseStream();

    return Image.FromStream(stream);

    }

     

    public bool IsReusable

    {

    get

    {

    return false;

    }

    }

    }

    }

  • 03-18-2008 10:52 AM In reply to

    Re: Thumbnails

    I see.

    The code of this service is thought to include in a master or any control which calls an Image. It dynamically renders the Image down to a size.

    It doesnt create a batch out of every file in the folder. You just replace the classic <IMG> src with the new adress of the Image service.

     

    *Freetime Freestyle DashCommerce development*

    Currently working on:
    ##############################################################
    · TagCloud - patching
    · Headline Generator 50%
    · Navigation XHTML with Images 80%
    · Extended Shopping Cart Widget - 5%
    · XML Sitemap Service Exporting for Google, Froogle what ever. 33%
    - JQuery Implementing for better JLib Support 70%
Page 1 of 2 (26 items) 1 2 Next >