Last active
August 29, 2015 14:03
-
-
Save avtehnik/2f529c259ea0b1350ce1 to your computer and use it in GitHub Desktop.
ios splashscreen generator
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 | |
$sizes = array( | |
array('n' => 'Default.png', 'w' => 320, 'h' => 480), | |
array('n' => '[email protected]', 'w' => 640, 'h' => 960), | |
array('n' => 'Default@2x~ipad.png', 'w' => 2048, 'h' => 1496), | |
array('n' => 'Default~ipad.png', 'w' => 768, 'h' => 1004), | |
array('n' => 'Default-Landscape.png', 'w' => 1024, 'h' => 768), | |
array('n' => '[email protected]', 'w' => 2048, 'h' => 1536), | |
array('n' => '[email protected]', 'w' => 640, 'h' => 1136), | |
array('n' => 'Default-Portrait.png', 'w' => 768, 'h' => 1024), | |
array('n' => '[email protected]', 'w' => 1536, 'h' => 2048), | |
array('n' => 'Default-Landscape~ipad.png', 'w' => 1024, 'h' => 748), | |
array('n' => 'Default-Portrait@2x~ipad.png', 'w' => 1536, 'h' => 2048), | |
array('n' => 'Default~@2x~ipad.png', 'w' => 1536, 'h' => 2008), | |
array('n' => 'screen-hdpi-landscape.png', 'w' => 800, 'h' => 480), | |
array('n' => 'screen-hdpi-portrait.png', 'w' => 480, 'h' => 800), | |
array('n' => 'screen-ldpi-landscape.png', 'w' => 320, 'h' => 200), | |
array('n' => 'screen-ldpi-portrait.png', 'w' => 200, 'h' => 320), | |
array('n' => 'screen-mdpi-landscape.png', 'w' => 480, 'h' => 320), | |
array('n' => 'screen-mdpi-portrait.png', 'w' => 320, 'h' => 480), | |
array('n' => 'screen-xhdpi-landscape.png', 'w' => 1280, 'h' => 720), | |
array('n' => 'screen-xhdpi-portrait.png', 'w' => 720, 'h' => 1280), | |
array('n' => 'icon-36-ldpi.png', 'w' => 36, 'h' => 36,'trancparent'=>true), | |
array('n' => 'icon-48-mdpi.png', 'w' => 48, 'h' => 48,'trancparent'=>true), | |
array('n' => 'icon-72-hdpi.png', 'w' => 72, 'h' => 72,'trancparent'=>true), | |
array('n' => 'icon-96-xhdpi.png', 'w' => 96, 'h' => 96,'trancparent'=>true), | |
array('n' => 'icon-144-xxhdpi.png', 'w' => 144, 'h' => 144,'trancparent'=>true), | |
); | |
ini_set("memory_limit", "900M"); | |
list($width_orig, $height_orig) = getimagesize('src.png'); | |
$src = 'src.png'; | |
if(!is_dir('./build')){ | |
mkdir('./build'); | |
} | |
foreach ($sizes as $imageSize) { | |
print_r($imageSize); | |
$ratio_orig = $width_orig / $height_orig; | |
$height = $width / $ratio_orig; | |
$images_orig = imagecreatefrompng($src); | |
$photoX = imagesx($images_orig); | |
$photoY = imagesy($images_orig); | |
$images_fin = imagecreatetruecolor($imageSize['w'], $imageSize['h']); | |
if($imageSize['trancparent']){ | |
imagealphablending($images_fin, false); | |
imagesavealpha($images_fin, true); | |
}else{ | |
$white = imagecolorallocate($images_fin, 255, 255, 255); | |
imagefill($images_fin, 0, 0, $white); | |
} | |
if ($imageSize['w'] > $imageSize['h']) { | |
$size = $imageSize['h']; | |
$xoffset = ($imageSize['w'] - $size) / 2; | |
$yoffset = 0; | |
} else { | |
$size = $imageSize['w']; | |
$yoffset = ($imageSize['h'] - $size) / 2; | |
$xoffset = 0; | |
} | |
$newwidth = $size; | |
$newheight = $size; | |
if(isset($imageSize['crop'])){ | |
$photoX = $photoX - $imageSize['crop']; | |
$photoY = $photoY - $imageSize['crop']; | |
} | |
imagecopyresized($images_fin, $images_orig, $xoffset, $yoffset, 0, 0, $newwidth, $newheight, $photoX, $photoY); | |
imagepng($images_fin, "build/" . $imageSize['n']); | |
imagedestroy($images_orig); | |
imagedestroy($images_fin); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment