本文整理汇总了PHP中S3::SaveFile方法的典型用法代码示例。如果您正苦于以下问题:PHP S3::SaveFile方法的具体用法?PHP S3::SaveFile怎么用?PHP S3::SaveFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类S3
的用法示例。
在下文中一共展示了S3::SaveFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: CreateThumb
//.........这里部分代码省略.........
$n_img = imagecreatefrompng($image);
break;
case IMAGETYPE_GIF:
$n_img = imagecreatefromgif($image);
break;
case 'image/svg+xml':
break;
default:
return false;
}
$dst_img = ImageCreateTrueColor($target_w, $target_h);
switch ($type) {
// fix for transparency issues
case IMAGETYPE_PNG:
imagealphablending($dst_img, true);
imagesavealpha($dst_img, true);
$transparent_color = imagecolorallocatealpha($dst_img, 0, 0, 0, 127);
imagefill($dst_img, 0, 0, $transparent_color);
break;
case IMAGETYPE_GIF:
$transparency_index = imagecolortransparent($dst_img);
if ($transparency_index >= 0) {
$transparent_color = imagecolorsforindex($dst_img, $transparency_index);
$transparency_index = imagecolorallocate($dst_img, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
imagefill($dst_img, 0, 0, $transparency_index);
imagecolortransparent($dst_img, $transparency_index);
}
break;
default:
break;
}
// (for testing) die('curr_w='.$curr_w.' curr_h='.$curr_h.' x_start='.$x_start.' y_start='.$y_start.' target_w='.$target_w.' target_h='.$target_h.' up_w='.$up_w.' up_h='.$up_h);
if ($type != 'image/svg+xml') {
imagecopyresampled($dst_img, $n_img, 0, 0, $x_start, $y_start, $target_w, $target_h, $up_w, $up_h);
}
//return $dst_img;
$full = $dir . 'thumbs/' . $filename;
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
switch ($ext) {
case 'jpg':
// save file on S3
if (FILES_ON_S3 == true) {
// write image and copy buffer
ob_start();
imagejpeg($dst_img, NULL, 100);
$contents = ob_get_contents();
ob_end_clean();
$meta = array('width' => $target_w, 'height' => $target_h);
S3::SaveContents($site, $type, 'thumbs/' . $filename, $contents, $meta, $folder);
} else {
// save file locally
imagejpeg($dst_img, $full, 100);
}
break;
case 'png':
// save file on S3
if (FILES_ON_S3 == true) {
// write image and copy buffer
ob_start();
imagepng($dst_img, NULL);
$contents = ob_get_contents();
ob_end_clean();
$meta = array('width' => $target_w, 'height' => $target_h);
S3::SaveContents($site, $type, 'thumbs/' . $filename, $contents, $meta, $folder);
} else {
// save file locally
imagepng($dst_img, $full);
}
break;
case 'gif':
// save file on S3
if (FILES_ON_S3 == true) {
// write image and copy buffer
ob_start();
imagegif($dst_img, null);
$meta = array();
$contents = ob_get_contents();
ob_end_clean();
S3::SaveContents($site, $type, 'thumbs/' . $filename, $contents, $meta, $folder);
} else {
// save file locally
imagegif($dst_img, $full);
}
break;
case 'svg':
// save file on S3
if (FILES_ON_S3 == true) {
S3::SaveFile($site, $type, 'thumbs/' . $filename, $image, $folder);
} else {
// save file locally
copy($image, $full);
}
break;
default:
return false;
return true;
}
}