原帖在 http://www.v2ex.com/t/38590
从一个页面上传一个图片 文件 JPG bmp 图片限制2M以内
然后用PHP 处理图片 分析图片尺寸 若图片为800*600 则分割成198*198的图片 12个 并显示出来
每张图片抛弃2px;
第一张图片对应原图片 左上角0,0,右下角198,198,第2张图片左上角200,0 右下角398,198
因为我对PHP不熟悉 网上又找不到类似的代码可供研究 又或者是SAE 的运行环境比较另类
我在某个代码上卡住了
isfeel.sinaapp.com/upload/index.html
上传后生成的图片有黑色的边 而不是我想要的效果
代码如下
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" cOntent="text/html; charset=" />
<title>html5 example: IMG Preview</title>
</head>
<body>
<?php
$s = new SaeStorage();
$name =$_FILES['viewFiles']['name'];
if ((($_FILES["viewFiles"]["type"] == "image/gif")
|| ($_FILES["viewFiles"]["type"] == "image/jpeg")
|| ($_FILES["viewFiles"]["type"] == "image/pjpeg"))
&& ($_FILES["viewFiles"]["size"] < 2000000))
{
if ($_FILES["viewFiles"]["error"] > 0)
{
echo "错误代码: " . $_FILES["viewFiles"]["error"] . "<br />";
}
else
{
echo "文件名称: " . $_FILES["viewFiles"]["name"] . "<br />";
echo "文件类型: " . $_FILES["viewFiles"]["type"] . "<br />";
echo "占用空间: " . ($_FILES["viewFiles"]["size"] / 1024) . " Kb<br />";
echo "缓存地址: " . $_FILES["viewFiles"]["tmp_name"] . "<br />";
$tmpfile=$_FILES["viewFiles"]["tmp_name"];
$tempcache=$_FILES["viewFiles"]["tmp_name"];
list($current_width, $current_height) = getimagesize($tmpfile);
echo "图片尺寸:".$current_width."X".$current_height."<br/>";
echo "操作完成..<br/>";
if ($current_width>200 || $current_width<2500 || $current_height>200 || $current_height<1500)
{
$left = 0;
$top = 0;
$crop_width = 198;
$crop_height = 198;
for ($i =1; $i<=9;$i++)
{
$canvas =imagecreatetruecolor($crop_width, $crop_height);
$current_image =imagecreatefromjpeg($tmpfile);
imagecopy($canvas, $current_image, 0, 0, $left, $top,$current_width, $current_height);
imagejpeg($canvas,$tempcache,85);
$targetfile=$i.".jpg";
$s->upload("upload",$targetfile,$tempcache);
$imgurl=$s->getUrl("upload",$targetfile);
echo "<img src='".$imgurl."?".time()."'/>";
imagedestroy($canvas);
imagedestroy($current_image);
$left+=3;
$top+=3;
}
}
else
{
echo "图片宽度小于200 或 大于3500像素";
echo "图片高度小于200 或 大于3500像素";
echo $current_width.$current_height;
}
//}
}
}
else
{
echo "图片不符合规范 JPG 2M字节以下";
}
?>
</body>
</html>
经过UPlaod.php处理的图片 是有黑边的
事情进行到这里就彻底卡住了 进行不下去了
然后又去玩网游去了
直到今天才想起来 还有这个坑没填上
所以想请V2ex上的朋友帮帮忙
要是再让我回到网游上边去 可能又要几个月才想得起来了
我这里 召唤一些大神们
@CoX
@zythum
@liyandong
@liyandong
@no2x
@galaxy11
@shiren1118
@twor2
@shiren1118
@blank_dlh
@jo32
@flyingnn
@jo32
@javaluo
@xmbaozi
@66
@wdd2007
@chaojie
@shiren1118
@66
@Even
@l0wkey
@yujnln
@Bob
从一个页面上传一个图片 文件 JPG bmp 图片限制2M以内
然后用PHP 处理图片 分析图片尺寸 若图片为800*600 则分割成198*198的图片 12个 并显示出来
每张图片抛弃2px;
第一张图片对应原图片 左上角0,0,右下角198,198,第2张图片左上角200,0 右下角398,198
因为我对PHP不熟悉 网上又找不到类似的代码可供研究 又或者是SAE 的运行环境比较另类
我在某个代码上卡住了
isfeel.sinaapp.com/upload/index.html
上传后生成的图片有黑色的边 而不是我想要的效果
代码如下
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" cOntent="text/html; charset=" />
<title>html5 example: IMG Preview</title>
</head>
<body>
<?php
$s = new SaeStorage();
$name =$_FILES['viewFiles']['name'];
if ((($_FILES["viewFiles"]["type"] == "image/gif")
|| ($_FILES["viewFiles"]["type"] == "image/jpeg")
|| ($_FILES["viewFiles"]["type"] == "image/pjpeg"))
&& ($_FILES["viewFiles"]["size"] < 2000000))
{
if ($_FILES["viewFiles"]["error"] > 0)
{
echo "错误代码: " . $_FILES["viewFiles"]["error"] . "<br />";
}
else
{
echo "文件名称: " . $_FILES["viewFiles"]["name"] . "<br />";
echo "文件类型: " . $_FILES["viewFiles"]["type"] . "<br />";
echo "占用空间: " . ($_FILES["viewFiles"]["size"] / 1024) . " Kb<br />";
echo "缓存地址: " . $_FILES["viewFiles"]["tmp_name"] . "<br />";
$tmpfile=$_FILES["viewFiles"]["tmp_name"];
$tempcache=$_FILES["viewFiles"]["tmp_name"];
list($current_width, $current_height) = getimagesize($tmpfile);
echo "图片尺寸:".$current_width."X".$current_height."<br/>";
echo "操作完成..<br/>";
if ($current_width>200 || $current_width<2500 || $current_height>200 || $current_height<1500)
{
$left = 0;
$top = 0;
$crop_width = 198;
$crop_height = 198;
for ($i =1; $i<=9;$i++)
{
$canvas =imagecreatetruecolor($crop_width, $crop_height);
$current_image =imagecreatefromjpeg($tmpfile);
imagecopy($canvas, $current_image, 0, 0, $left, $top,$current_width, $current_height);
imagejpeg($canvas,$tempcache,85);
$targetfile=$i.".jpg";
$s->upload("upload",$targetfile,$tempcache);
$imgurl=$s->getUrl("upload",$targetfile);
echo "<img src='".$imgurl."?".time()."'/>";
imagedestroy($canvas);
imagedestroy($current_image);
$left+=3;
$top+=3;
}
}
else
{
echo "图片宽度小于200 或 大于3500像素";
echo "图片高度小于200 或 大于3500像素";
echo $current_width.$current_height;
}
//}
}
}
else
{
echo "图片不符合规范 JPG 2M字节以下";
}
?>
</body>
</html>
经过UPlaod.php处理的图片 是有黑边的
事情进行到这里就彻底卡住了 进行不下去了
然后又去玩网游去了
直到今天才想起来 还有这个坑没填上
所以想请V2ex上的朋友帮帮忙
要是再让我回到网游上边去 可能又要几个月才想得起来了
我这里 召唤一些大神们
@CoX
@zythum
@liyandong
@liyandong
@no2x
@galaxy11
@shiren1118
@twor2
@shiren1118
@blank_dlh
@jo32
@flyingnn
@jo32
@javaluo
@xmbaozi
@66
@wdd2007
@chaojie
@shiren1118
@66
@Even
@l0wkey
@yujnln
@Bob
