Solved

resize image - sql or C#

Posted on 2011-09-27
2
306 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
Comment Utility
0
 

Author Comment

by:johnkainn
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now