1

I have done image resizing while allowing user to upload a specific size image and then crop them to different dimension i have also used jCrop in project to allow users to upload a image of specific size and then select the image area & crop it accordingly.

In new project i have a requirement where user can upload any size image which is at least larger than 500Px in width and then i have to allow user to select the part of image using jCrop and then save image in different dimension of 475x313 , 310x205 while maintaining the aspect ration.

I can do it with if i allow the used to upload a fixed size image but i am not sure how i can handle variable size image.

I also need to display the image uploaded before cropping in a fixed size box.. let us say 300x200. in this area i have to allow the user to select the part of the image before i can crop.

Issue i am facing is how to handle variable length image and show it is a fixed image box of 300x200px.

2 Answers 2

1

I wrote an article on using jCrop with dynamically-resized uploaded images, which seems to be what you're needing.

If you're looking for an open-source ASP.NET control that does it for you, check out cropimage.net.

Sign up to request clarification or add additional context in comments.

Comments

0

Want to going to by programmatically than you can try this :

if you are using file upload for upload images

    string path = Path.GetFileName(fileuploaderID.PostedFile.FileName); 
    ConvertThumbnails(width, height, fileuploaderID.FileBytes, path);

your function

       public void ConvertThumbnails(int width, int height, byte[] filestream, string path)
      {
        // create an image object, using the filename we just retrieved

        var stream = new MemoryStream(filestream);
        System.Drawing.Image image = System.Drawing.Image.FromStream(stream);

         try
              {  
                int fullSizeImgWidth = image.Width;
                int fullSizeImgHeight = image.Height;
                float imgWidth = 0.0F;
                float imgHeight = 0.0F;
                imgWidth = width;
                imgHeight = height;

                Bitmap thumbNailImg = new Bitmap(image, (int)imgWidth, (int)imgHeight);
                MemoryStream ms = new MemoryStream();
                // Save to memory using the Jpeg format
                thumbNailImg.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                // read to end
                byte[] bmpBytes = ms.GetBuffer();
                item.Attachments.Add(path, bmpBytes);
                thumbNailImg.Dispose();
                ms.Close();

        }
        catch (Exception)
        {
            image.Dispose();
        }
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.