我试图制作一个图片库,但我被困在缩小脚本上。我把它做成了函数。原始输入$_FILES['image']
替换为$original
。
我很确定这部分没问题,但我添加它是为了更好地定位。
$orig_udaje = getimagesize($original['tmp_name']);
$orig_sirka = $orig_udaje[0]; //original width
$orig_vyska = $orig_udaje[1]; //original height
$orig_typ = $orig_udaje[2]; //type of original image
$div_size = 150; //size of image div = size of future thumbnail's smaller side
// choosing smaller side & defining resizing scale
if ($orig_sirka>$orig_vyska)
{
$mira = $orig_vyska / $div_size;
}
else
{
$mira = $orig_sirka / $div_size;
}
$nahled_sirka = $orig_sirka / $mira;
$nahled_vyska = $orig_vyska / $mira;
我认为麻烦的部分在本文下面的某个地方。
$nahled_cache = imagecreatetruecolor($nahled_sirka, $nahled_vyska);
imagecolortransparent($nahled_cache, "0, 0, 0");
if ($orig_typ == "image/jpeg")
{
$nahled_tvorba = imagecreatefromjpeg($original['tmp_name']);
imagecopyresampled($nahled_cache, $nahled_tvorba, 0, 0, 0, 0, $nahled_sirka, $nahled_vyska, $orig_sirka, $orig_vyska);
imagejpeg($nahled_cache, "/data/images/gallery/thumbs/output.jpg");
imagejpeg($original['tmp_name'], "/data/images/gallery/originals/output.jpg");
unlink($original['tmp_name']);
}
if ($orig_typ == "image/png")
{
$obrazek_tvorba = imagecreatefrompng($original['tmp_name']);
imagecopyresampled($nahled_cache, $nahled_tvorba, 0, 0, 0, 0, $nahled_sirka, $nahled_vyska, $orig_sirka, $orig_vyska);
imagepng($nahled_cache, "/data/images/gallery/thumbs/output.png");
imagepng($original['tmp_name'], "/data/images/gallery/originals/output.png");
unlink($original['tmp_name']);
}
感谢您的意见。