Solved

resize image - sql or C#

Posted on 2011-09-27
2
335 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

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…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

809 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