Solved

resize image - sql or C#

Posted on 2011-09-27
2
347 Views
Last Modified: 2012-05-12
I select a column from a table in sql 2008.
The fields in the column can have text and images.
If the width of the image is >450 px then I would like to resize it. So that the width becomes 450px and keep the aspect ratio.
Should I do this in sql query or C#? Can you provide an example how is best to do this?
Here is data from a field in the table:
Some Text <img alt="" style="width: 640px; height: 278px;" src="/upload/MyImage.gif" />  
0
Comment
Question by:johnkainn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 500 total points
ID: 36708393
0
 

Author Comment

by:johnkainn
ID: 36709681
Thank you. I rewrote the function as I do not want to modify the size of the image it self, but just resize it in the html text.

 
public string[] ResizeImage(int width,int height)
    {
        int maxWidth = 500;
        if(maxWidth<=width){
            width = maxWidth;
            height = height * width / maxWidth;
        }
        string[] arr = { width.ToString(), height.ToString() };
        return arr;
    }

Open in new window


I am not sure how I loop the string call the method and resize height and width in the string it if the width exceeds 500 px.  
Here is an example of text string with 2 images. After modification the width is 500 (1000) and height is 250(500). The second image is unchanged as the width is less then 500px.
Before:
Description of Pic1 <img alt="" style="width: 1000px; height: 500px;" src="/upload/MyImage.gif" /> and details of pic2 <img alt="" style="width: 300px; height: 278px;" src="/upload/MyImage2.gif" />
After:
Description of Pic1 <img alt="" style="width: 500px; height: 250px;" src="/upload/MyImage.gif" /> and details of pic2 <img alt="" style="width: 300px; height: 278px;" src="/upload/MyImage2.gif" />
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question