Обучение/Помощь новичкам | Нужна помощь с изображениями
Всем привет,нужна помощь с сохранением изображений,вот код подскажите что не так пожалуйста.
function resize($file_input, $file_output, $w_o, $h_o, $percent = false) {
list($w_i, $h_i, $type) = getimagesize($file_input);
if (!$w_i || !$h_i) {
echo 'Невозможно получить длину и ширину изображения';
return;
}
$types = array('','gif','jpeg','png');
$ext = $types[$type];
if ($ext) { $func = 'imagecreatefrom'.$ext;
$img = $func($file_input); } else { echo 'Некорректный формат файла';
return; }
if ($percent) {$w_o *= $w_i / 100;
$h_o *= $h_i / 100;
}if (!$h_o) $h_o = $w_o/($w_i/$h_i);
if (!$w_o) $w_o = $h_o/($h_i/$w_i);$img_o = imagecreatetruecolor($w_o, $h_o);
imagecopyresampled($img_o, $img, 0, 0, 0, 0, $w_o, $h_o, $w_i, $h_i);
if ($type == 2) {
return imagejpeg($img_o,$file_output,100);
} else {$func = 'image'.$ext;
return $func($img_o,$file_output);}
}
function crop($file_input, $file_output, $crop = 'square',$percent = false) {
list($w_i, $h_i, $type) = getimagesize($file_input);
if (!$w_i || !$h_i) {
echo 'Невозможно получить длину и ширину изображения';
return;
}
$types = array('','gif','jpeg','png');
$ext = $types[$type];
if ($ext) {
$func = 'imagecreatefrom'.$ext;
$img = $func($file_input);
} else {
echo 'Некорректный формат файла';
return;
}
if ($crop == 'square') {
$min = $w_i;
if ($w_i > $h_i) $min = $h_i;
$w_o = $h_o = $min;
} else {
list($x_o, $y_o, $w_o, $h_o) = $crop;if ($percent) {
$w_o *= $w_i / 100;
$h_o *= $h_i / 100;
$x_o *= $w_i / 100;
$y_o *= $h_i / 100;
}
if ($w_o < 0) $w_o += $w_i;
$w_o -= $x_o;
if ($h_o < 0) $h_o += $h_i;
$h_o -= $y_o;
}
$img_o = imagecreatetruecolor($w_o, $h_o);
imagecopy($img_o, $img, 0, 0, $x_o, $y_o, $w_o, $h_o);
if ($type == 2) {
return imagejpeg($img_o,$file_output,100);
} else {
$func = 'image'.$ext;
return $func($img_o,$file_output);
}
}
mysql_query("INSERT INTO `foto` (`name`,`opis`) values('none','non')");
$id_foto=mysql_insert_id();
$imgc = @imagecreatefromstring(file_get_contents($_FILES['uploadfile']['tmp_name']))
$img_x = imagesx($imgc);
$img_y = imagesy($imgc);
if ($img_x == $img_y)
{
$dstW = 48; // ширина
$dstH = 48; // высота
}
elseif ($img_x > $img_y)
{
$prop = $img_x / $img_y;
$dstW = 48;
$dstH = ceil($dstW / $prop);
}
else
{
$prop = $img_y / $img_x;
$dstH = 48;
$dstW = ceil($dstH / $prop);
}
$screen = imagecreatetruecolor($dstW, $dstH);
imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
//imagedestroy($imgc);
imagejpeg($screen,H."sys/gallery/48/$id_foto.jpg",90);
@chmod(H."sys/gallery/48/$id_foto.jpg",0777);
imagedestroy($screen);
if ($img_x == $img_y)
{
$dstW = 128; // ширина
$dstH = 128; // высота
}
elseif ($img_x > $img_y)
{
$prop = $img_x / $img_y;
$dstW = 128;
$dstH = ceil($dstW / $prop);
}
else
{
$prop = $img_y / $img_x;
$dstH = 128;
$dstW = ceil($dstH / $prop);
}
$screen = imagecreatetruecolor($dstW, $dstH);
imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
//imagedestroy($imgc);
imagejpeg($screen,H."sys/gallery/128/$id_foto.jpg",90);
@chmod(H."sys/gallery/128/$id_foto.jpg",0777);
imagedestroy($screen);
if ($img_x > 640 || $img_y > 640)
{
if ($img_x == $img_y)
{
$dstW = 640; // ширина
$dstH = 640; // высота
}
elseif ($img_x > $img_y)
{
$prop = $img_x / $img_y;
$dstW = 640;
$dstH = ceil($dstW / $prop);
}
else
{
$prop = $img_y / $img_x;
$dstH = 640;
$dstW = ceil($dstH / $prop);
}
$screen = imagecreatetruecolor($dstW, $dstH);
imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
// imagedestroy($imgc);
imagejpeg($screen,H."sys/gallery/640/$id_foto.jpg",90);
imagedestroy($screen);
imagejpeg($imgc,H."sys/gallery/foto/$id_foto.jpg",90);
@chmod(H."sys/gallery/foto/$id_foto.jpg",0777);
}
else
{
imagejpeg($imgc,H."sys/gallery/640/$id_foto.jpg",90);
imagejpeg($imgc,H."sys/gallery/foto/$id_foto.jpg",90);
@chmod(H."sys/gallery/foto/$id_foto.jpg",0777);
}
@chmod(H."sys/gallery/640/$id_foto.jpg",0777);
imagedestroy($imgc);
crop(H."sys/gallery/640/$id_foto.jpg", H."sys/gallery/50/$id_foto.tmp.jpg");
resize(H."sys/gallery/50/$id_foto.tmp.jpg", H."sys/gallery/50/$id_foto.jpg", 50, 50);
@chmod(H."sys/gallery/50/$id_foto.jpg",0777);
@unlink(H."sys/gallery/50/$id_foto.tmp.jpg");
function resize($file_input, $file_output, $w_o, $h_o, $percent = false) {
list($w_i, $h_i, $type) = getimagesize($file_input);
if (!$w_i || !$h_i) {
echo 'Невозможно получить длину и ширину изображения';
return;
}
$types = array('','gif','jpeg','png');
$ext = $types[$type];
if ($ext) { $func = 'imagecreatefrom'.$ext;
$img = $func($file_input); } else { echo 'Некорректный формат файла';
return; }
if ($percent) {$w_o *= $w_i / 100;
$h_o *= $h_i / 100;
}if (!$h_o) $h_o = $w_o/($w_i/$h_i);
if (!$w_o) $w_o = $h_o/($h_i/$w_i);$img_o = imagecreatetruecolor($w_o, $h_o);
imagecopyresampled($img_o, $img, 0, 0, 0, 0, $w_o, $h_o, $w_i, $h_i);
if ($type == 2) {
return imagejpeg($img_o,$file_output,100);
} else {$func = 'image'.$ext;
return $func($img_o,$file_output);}
}
function crop($file_input, $file_output, $crop = 'square',$percent = false) {
list($w_i, $h_i, $type) = getimagesize($file_input);
if (!$w_i || !$h_i) {
echo 'Невозможно получить длину и ширину изображения';
return;
}
$types = array('','gif','jpeg','png');
$ext = $types[$type];
if ($ext) {
$func = 'imagecreatefrom'.$ext;
$img = $func($file_input);
} else {
echo 'Некорректный формат файла';
return;
}
if ($crop == 'square') {
$min = $w_i;
if ($w_i > $h_i) $min = $h_i;
$w_o = $h_o = $min;
} else {
list($x_o, $y_o, $w_o, $h_o) = $crop;if ($percent) {
$w_o *= $w_i / 100;
$h_o *= $h_i / 100;
$x_o *= $w_i / 100;
$y_o *= $h_i / 100;
}
if ($w_o < 0) $w_o += $w_i;
$w_o -= $x_o;
if ($h_o < 0) $h_o += $h_i;
$h_o -= $y_o;
}
$img_o = imagecreatetruecolor($w_o, $h_o);
imagecopy($img_o, $img, 0, 0, $x_o, $y_o, $w_o, $h_o);
if ($type == 2) {
return imagejpeg($img_o,$file_output,100);
} else {
$func = 'image'.$ext;
return $func($img_o,$file_output);
}
}
mysql_query("INSERT INTO `foto` (`name`,`opis`) values('none','non')");
$id_foto=mysql_insert_id();
$imgc = @imagecreatefromstring(file_get_contents($_FILES['uploadfile']['tmp_name']))
$img_x = imagesx($imgc);
$img_y = imagesy($imgc);
if ($img_x == $img_y)
{
$dstW = 48; // ширина
$dstH = 48; // высота
}
elseif ($img_x > $img_y)
{
$prop = $img_x / $img_y;
$dstW = 48;
$dstH = ceil($dstW / $prop);
}
else
{
$prop = $img_y / $img_x;
$dstH = 48;
$dstW = ceil($dstH / $prop);
}
$screen = imagecreatetruecolor($dstW, $dstH);
imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
//imagedestroy($imgc);
imagejpeg($screen,H."sys/gallery/48/$id_foto.jpg",90);
@chmod(H."sys/gallery/48/$id_foto.jpg",0777);
imagedestroy($screen);
if ($img_x == $img_y)
{
$dstW = 128; // ширина
$dstH = 128; // высота
}
elseif ($img_x > $img_y)
{
$prop = $img_x / $img_y;
$dstW = 128;
$dstH = ceil($dstW / $prop);
}
else
{
$prop = $img_y / $img_x;
$dstH = 128;
$dstW = ceil($dstH / $prop);
}
$screen = imagecreatetruecolor($dstW, $dstH);
imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
//imagedestroy($imgc);
imagejpeg($screen,H."sys/gallery/128/$id_foto.jpg",90);
@chmod(H."sys/gallery/128/$id_foto.jpg",0777);
imagedestroy($screen);
if ($img_x > 640 || $img_y > 640)
{
if ($img_x == $img_y)
{
$dstW = 640; // ширина
$dstH = 640; // высота
}
elseif ($img_x > $img_y)
{
$prop = $img_x / $img_y;
$dstW = 640;
$dstH = ceil($dstW / $prop);
}
else
{
$prop = $img_y / $img_x;
$dstH = 640;
$dstW = ceil($dstH / $prop);
}
$screen = imagecreatetruecolor($dstW, $dstH);
imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
// imagedestroy($imgc);
imagejpeg($screen,H."sys/gallery/640/$id_foto.jpg",90);
imagedestroy($screen);
imagejpeg($imgc,H."sys/gallery/foto/$id_foto.jpg",90);
@chmod(H."sys/gallery/foto/$id_foto.jpg",0777);
}
else
{
imagejpeg($imgc,H."sys/gallery/640/$id_foto.jpg",90);
imagejpeg($imgc,H."sys/gallery/foto/$id_foto.jpg",90);
@chmod(H."sys/gallery/foto/$id_foto.jpg",0777);
}
@chmod(H."sys/gallery/640/$id_foto.jpg",0777);
imagedestroy($imgc);
crop(H."sys/gallery/640/$id_foto.jpg", H."sys/gallery/50/$id_foto.tmp.jpg");
resize(H."sys/gallery/50/$id_foto.tmp.jpg", H."sys/gallery/50/$id_foto.jpg", 50, 50);
@chmod(H."sys/gallery/50/$id_foto.jpg",0777);
@unlink(H."sys/gallery/50/$id_foto.tmp.jpg");
DELETED
31 марта 2017, в 19:27
Delete
shadrvlad (31.03.2017 в 19:27)
225503810 , обменники кодом? нее, не слышал
225503810 , обменники кодом? нее, не слышал
нет