Add a space for the image and save the file to the server

I have a script that generates some HTML for newsletters. I float with "align = left" and wrap the text around it. I use the inline CSS style, in this case margin-right, to give the image some breathing room. Outlook ignores this. Outlook also ignores padding - I even tried 10px border-right, it ignored it too.

I can not change the layout and put the image in the table. I am thinking of using GD to manipulate the image by adding 8px spaces to the right. The trick, as this is a newsletter published to thousands of people, is that I then need to save the modified image on the server somewhere so that I can link to it. I do not want to generate this on the fly.

I have zero experience with GD or saving files in place with PHP. Here is my image code:

<img alt="<?php print $main2['title']; ?>" height="127" width="185" src="http://www.mydomain.com/uploads/<?php print $main2['filename']; ?>" align="left" style="margin:8px 8px 0 0;"/>
+1
source share
3 answers

You can definitely rely on CSS for newsletters - only certain properties and built-in. We are launching a very successful set of campaigns, and the newsletters look just fine for everyone.

, -, .

, , , , - , , . , , , , , ?

FWIW, GD - , , - script, - :

// get image
$url = 'myimage.jpg';
$src = imagecreatefromjpeg($url);

// dimensions (just to be safe, should always be 185x127 though)
$src_wide = imagesx($src);
$src_high = imagesy($src);

// set white padding color
$clear = array('red'=>255,'green'=>255,'blue'=>255);

// new image dimensions with right padding
$dst_wide = $src_wide+8;
$dst_high = $src_high+8;

// New resource image at new size
$dst = imagecreatetruecolor($dst_wide, $dst_high);

// fill the image with the white padding color
$clear = imagecolorallocate( $dst, $clear["red"], $clear["green"], $clear["blue"]);
imagefill($dst, 0, 0, $clear);

// copy the original image on top of the new one
imagecopymerge($dst,$src,0,8,0,0,$src_wide,$src_high, 100);

// store the new image in tmp directory
$pth = 'tmp/myimage.jpg';
imagejpeg($dst, $pth, 100);

// free resources
imagedestroy($src);
imagedestroy($dst); 
+3

css , , , .

. , . css , , , .

, , , ?

, , GD, script "" .

: http://www.imagemagick.org/Usage/thumbnails/#pad

css , .

, , , . mailchimp free accounts, , .

+1

gif spacer ( html yeah):

<img alt="" height="127" width="8" src="http://www.mydomain.com/spacer.gif" align="left" />

A Spacer - 1x1, , html, .

, , html/css. , - html-: http://www.campaignmonitor.com/design-guidelines/

+1

Source: https://habr.com/ru/post/1537052/


All Articles