我一直在與谷歌支持聯繫。他們給了我這個代碼。儘管如此,我還沒有機會去測試它。
<?php
include 'lib/cms.php';
require_once('config.php');
require_once(MVC_ROOT . 'models/App.php');
ini_set("memory_limit", "-1M");
ini_set("max_input_time", "-1");
ini_set("max_execution_time", "-1");
set_time_limit(0);
ignore_user_abort();
$copyOrMove = (SYSTEM_PLATFORM == 'gogrid') ? 'cp' : 'mv';
$cms = new CMS();
$dbh = $cms->dbh;
$data = $_POST['data'];
//$appcode = $cms->safeInput($_REQUEST['app']);
$appcode = $cms->getAppcode();
$type = $_REQUEST['type'];
$appdir = '../apps/' . $appcode;
if (!file_exists($appdir)) mkdir($appdir);
if (!file_exists($appdir . '/images')) mkdir($appdir . '/images');
if (!file_exists($appdir . '/images/org')) mkdir($appdir . '/images/org');
if (!file_exists($appdir . '/images/gallery')) mkdir($appdir . '/images/gallery');
if (!file_exists($appdir . '/images/30')) mkdir($appdir . '/images/30');
if (!file_exists($appdir . '/images/75')) mkdir($appdir . '/images/75');
if (!file_exists($appdir . '/images/200')) mkdir($appdir . '/images/200');
if (!file_exists($appdir . '/images/resources')) mkdir($appdir . '/images/resources');
if (!file_exists($appdir . '/attachments')) mkdir($appdir . '/attachments');
if ($type == "image") {
$filename = 'homepage-' . date("Ymd-His") . '.png';
$dir = "../apps/" . $appCode . "/images";
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
//first lets delete the old ones...
foreach (glob("../apps/" . $appcode . "/images/homepage*.png") as $killfilename) {
echo "$killfilename size " . filesize($killfilename) . "\n";
unlink($killfilename);
exec("gsutil -m rm gs://gs.appbuild.io/apps/$appcode/images/homepage*.png");
}
//$filename='homepage.png';
$file = "../apps/$appcode/images/" . $filename;
$uri = substr($data, strpos($data, ",") + 1);
file_put_contents($file, base64_decode($uri));
$dir = "../apps/" . $appcode . "/images/resources";
resizeImage($file, 640, 960, $dir . "/[email protected]");
resizeImage($file, 640, 1136, $dir . "/[email protected]");
resizeImage($file, 320, 480, $dir . "/Default.png");
$pathArray = array("../apps/$appcode/images/resources/[email protected]","../apps/$appcode/images/resources/[email protected]","../apps/$appcode/images/resources/Default.png");
exec("gsutil $copyOrMove ../apps/$appcode/images/$filename gs://gs.appbuild.io/apps/$appcode/images/");
exec("gsutil -m $copyOrMove ". implode(' ',$pathArray) ." gs://gs.appbuild.io/apps/$appcode/images/resources/");
$sql = "INSERT INTO appearance SET appearance_background_image='$filename', app_code='$appcode' ON DUPLICATE KEY UPDATE appearance_background_image='$filename'";
$stmt = $dbh->query($sql);
$dbh = null;
// return the filename
echo URL_CDN_ROOT . "apps/$appcode/images/" . $filename;
} else if ($type == "icon") {
$size = $_REQUEST['size'];
$filename = 'icon_' . $size . '.png';
$dir = "../apps/" . $appcode . "/images/resources";
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
$file = $dir . "/$filename";
$uri = substr($data, strpos($data, ",") + 1);
file_put_contents($file, base64_decode($uri));
resizeImage($file, 57, 57, $dir . "/icon_57.png");
resizeImage($file, 57, 57, $dir . "/icon.png");
resizeImage($file, 72, 72, $dir . "/icon_72.png");
resizeImage($file, 114, 114, $dir . "/icon_114.png");
resizeImage($file, 114, 114, $dir . "/[email protected]");
resizeImage($file, 120, 120, $dir . "/icon_120.png");
resizeImage($file, 175, 175, $dir . "/icon_175.png");
resizeImage($file, 1024, 1024, $dir . "/icon_1024.png");
$filepaths = array($filename, "icon_57.png", "icon.png", "icon_72.png", "icon_114.png", "[email protected]", "icon_120.png", "icon_175.png", "icon_1024.png");
$fromArray = array();
foreach ($filepaths as $filenm){
$fromArray[] = "../apps/$appcode/images/resources/$filenm";
}
exec("gsutil -m $copyOrMove ". implode(' ', $fromArray) ." gs://gs.appbuild.io/apps/$appcode/images/resources/");
$app = new App($appcode);
$app->setAppIcon(implode(',', $filepaths));
echo URL_CDN_ROOT . "apps/$appcode/images/resources/$filename";
}
if (SYSTEM_PLATFORM == 'computeengine' && $appcode != '') delTree("../apps/$appcode");
function resizeImage($filename, $new_width, $new_height, $dirname)
{
list($width, $height) = getimagesize($filename);
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefrompng($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
//$newfilename = $dir . "/icon_" . $new_width . ".png";
imagepng($image_p, $dirname);
}
function delTree($dir) {
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file) {
(is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
}
return rmdir($dir);
}
?>
我已聯繫Google支持,但顯然他們也沒有關於此的任何信息。他們在問開發商。如果他們能給我提供答案,我會在這裏發佈答案。 – robwithhair