[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

resize image - sql or C#

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

656 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