Created
March 11, 2014 18:33
-
-
Save alastairjwright/9492099 to your computer and use it in GitHub Desktop.
Create html email from sliced psd images.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 1. slice psd into rows | |
// 2. slice up rows into columns | |
// 3. export slices, if over 100 images, add a 0 to 2 digit numbers, | |
// so that php loops through in order. | |
// (e.g. image_53.jpg needs to be image_053.jpg) | |
// there's an app called NameChanger which will save you time | |
// http://www.mrrsoftware.com/MRRSoftware/NameChanger.html | |
// 4. set page width and other variables below | |
// 5. run build.php and POW! there's your html! | |
// (doesn't add links or spacer gifs, so will need to do that manually) | |
define('PAGEWIDTH', 740); | |
define('IMAGE_PATH', 'images/'); | |
define('BG_COLOR', '#000000'); | |
$dh = opendir(IMAGE_PATH); | |
$current_width = 0; | |
$email = '<html lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
</head> | |
<body> | |
<center> | |
<table width="'.PAGEWIDTH.'" cellpadding="0" cellspacing="0" border="0" style="border-collapse: collapse; table-layout-fixed; border-spacing:0;"> | |
<tr style="border: none; margin:0px; padding:0px;">'; | |
while (($filename = readdir($dh)) !== false) { | |
if (filetype(IMAGE_PATH . $filename) !== 'dir') { // do cool shit | |
$size = getimagesize(IMAGE_PATH.$filename); | |
if ($current_width === PAGEWIDTH) { | |
$current_width = 0; | |
$email .= "\n\t".'</tr>'; | |
$email .= "\n".'</table>'; | |
$email .= "\n".'<table width="'.PAGEWIDTH.'" height="'.$size[1].'" cellpadding="0" cellspacing="0" border="0" style="border-collapse: collapse; border-spacing:0;">'; | |
$email .= "\n\t".'<tr style="border: none; margin:0px; padding:0px;">'; | |
} | |
$email .= "\n\t\t".'<td align="left" width="'.$size[0].'" height="'.$size[1].'" bgcolor="'.BG_COLOR.'" style="border: none; margin:0px; padding:0px;">'; | |
$email .= "\n\t\t\t".'<img src="'.IMAGE_PATH.$filename.'" alt="" width="'.$size[0].'" height="'.$size[1].'" border="0" style="display: block; border: none; margin:0px; padding:0px; line-height: 50%" />'; | |
$email .= "\n\t\t".'</td>'; | |
$current_width += $size[0]; | |
} | |
} | |
$email .= "\n\t".'</tr>'; | |
$email .= "\n".'</table>'; | |
$email .= "\n".'</body>'; | |
$email .= "\n".'</html>'; | |
echo $email; | |
file_put_contents('index.html', $email); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment