?
Solved

resize image - sql or C#

Posted on 2011-09-27
2
Medium Priority
?
352 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 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

752 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