How to create max-width and max-height effect for image sent in HTML email?

My application sends HTML letters containing one or more images of unknown size and width / height. The effect I want

<img style="max-width: 200px; max-height: 200px;" src="..." />

however, it seems that most email clients, including Gmail and Outlook 2010, ignore this css. The ease of setting the width and height does not work, because the image is not square, and I do not know the size and ratio ahead of time.

+5
source share
5 answers

: / html.

, ( :)).

+6

, CSS, .

.

, , , @Groovetrain, , .

+4

, , Groovetrain, -

  • , , .
  • , .
  • (, , ), , .

API, , , , .

+1

, , . , Groovetrain - HTML- - - # ASP.NET, 600, :

string imgPth = HttpContext.Current.Server.MapPath("/images/yourimage.jpg");
System.Drawing.Image img = System.Drawing.Image.FromFile(imgPth);
string emailImage = "<img src='http://www.yourdomain.com/images/yourimage.jpg'";
if (img.Width > 600)
    emailImage += " width='600' style='width:600px;'";
emailImage += "/>";

, , emailImage .

0

:

<table width="100%"> <!-- a width 100% container -->
   <tr>
      <td></td> <!-- an empty cell, which will adapt its width -->
      <td width="200"> <!-- it like max-width:200px -->
          <img src="your_image" width="100%" />
      </td>
      <td></td> <!-- another empty cell, which will adapt its width -->
   </tr>
</table>

. 200 , ! ! , , 1- ( , !)

For max-height, I have no idea ... In this case, the height will be automatically calculated!

Hope you help!

Edit: I agree with the best answer! If the script creates your email, ask the script to pick the width and height and adapt your code. it should work ...

0
source

All Articles