mrsmile
Новичок
непонятно с gd - gif формат
есть скрипт который загружает картинку подгоняет под нужный размер и переводит в jpeg все вроде бы работает но на некоторых картинках gif выдают ошибки такого рода
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in Z:\home\1c-freelance.co\www\upload.php on line 27
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'Z:\tmp\php4519.tmp' is not a valid JPEG file in Z:\home\1c-freelance.co\www\upload.php on line 27
Warning: imagesx(): supplied argument is not a valid Image resource in Z:\home\1c-freelance.co\www\upload.php on line 28
Warning: imagesy(): supplied argument is not a valid Image resource in Z:\home\1c-freelance.co\www\upload.php on line 29
Warning: Division by zero in Z:\home\1c-freelance.co\www\upload.php on line 32
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in Z:\home\1c-freelance.co\www\upload.php on line 33
Warning: imagejpeg(): supplied argument is not a valid Image resource in Z:\home\1c-freelance.co\www\upload.php on line 39
Warning: Division by zero in Z:\home\1c-freelance.co\www\upload.php on line 42
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in Z:\home\1c-freelance.co\www\upload.php on line 43
Warning: imagecopyresized(): supplied argument is not a valid Image resource in Z:\home\1c-freelance.co\www\upload.php on line 45
Warning: imagejpeg(): supplied argument is not a valid Image resource in Z:\home\1c-freelance.co\www\upload.php on line 47
Warning: Cannot modify header information - headers already sent by (output started at Z:\home\1c-freelance.co\www\upload.php:27) in Z:\home\1c-freelance.co\www\upload.php on line 49
Warning: Cannot modify header information - headers already sent by (output started at Z:\home\1c-freelance.co\www\upload.php:27) in Z:\home\1c-freelance.co\www\upload.php on line 65
вот сам скрипт
есть скрипт который загружает картинку подгоняет под нужный размер и переводит в jpeg все вроде бы работает но на некоторых картинках gif выдают ошибки такого рода
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in Z:\home\1c-freelance.co\www\upload.php on line 27
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'Z:\tmp\php4519.tmp' is not a valid JPEG file in Z:\home\1c-freelance.co\www\upload.php on line 27
Warning: imagesx(): supplied argument is not a valid Image resource in Z:\home\1c-freelance.co\www\upload.php on line 28
Warning: imagesy(): supplied argument is not a valid Image resource in Z:\home\1c-freelance.co\www\upload.php on line 29
Warning: Division by zero in Z:\home\1c-freelance.co\www\upload.php on line 32
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in Z:\home\1c-freelance.co\www\upload.php on line 33
Warning: imagejpeg(): supplied argument is not a valid Image resource in Z:\home\1c-freelance.co\www\upload.php on line 39
Warning: Division by zero in Z:\home\1c-freelance.co\www\upload.php on line 42
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in Z:\home\1c-freelance.co\www\upload.php on line 43
Warning: imagecopyresized(): supplied argument is not a valid Image resource in Z:\home\1c-freelance.co\www\upload.php on line 45
Warning: imagejpeg(): supplied argument is not a valid Image resource in Z:\home\1c-freelance.co\www\upload.php on line 47
Warning: Cannot modify header information - headers already sent by (output started at Z:\home\1c-freelance.co\www\upload.php:27) in Z:\home\1c-freelance.co\www\upload.php on line 49
Warning: Cannot modify header information - headers already sent by (output started at Z:\home\1c-freelance.co\www\upload.php:27) in Z:\home\1c-freelance.co\www\upload.php on line 65
вот сам скрипт
PHP:
<?php
session_start();
//header ('Content-type: image/gif, image/jpg, image/jpeg, image/png, image/tif');
$_SESSION['pustoi'] = 'hidden';
$_SESSION['ok'] = 'hidden';
$_SESSION['errorFormat'] = 'hidden';
$q = 1000;
$n=0;
$whitelist = array(".jpg",".jpeg", ".png", ".gif", ".tif");
foreach ($whitelist as $item) {
$n += 1;
if(preg_match("/$item\$/i", $_FILES['fileField']['name'])) {
$uploaddir = 'image/';
$uploadfile_big = $uploaddir . $_SESSION['idUser'].'_big.jpg';
$uploadfile = $uploaddir . $_SESSION['idUser'].'.jpg';
// if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
// echo "File is valid, and was successfully uploaded.\n";
// exit;
// }
// else {
// echo "File uploading failed.\n";
// exit;
// }
$imname = $_FILES['fileField']['tmp_name'];
// echo $_FILES['fileField']['tmp_name'];
$im = imagecreatefromjpeg("$imname");
$ox = imagesx($im);
$oy = imagesy($im);
$nx_big = 200;
$ny_big = floor($oy*($nx_big/$ox));
$nm_big = imagecreatetruecolor($nx_big, $ny_big);
if($ox > $nx_big){
imagecopyresized($nm_big, $im, 0, 0, 0, 0, $nx_big, $ny_big ,$ox, $oy);
imagejpeg($nm_big, $uploadfile_big, $q);
}
else{
imagejpeg($im, $uploadfile_big, $q);
}
$nx = 88;
$ny = floor($oy*($nx/$ox));
$nm = imagecreatetruecolor($nx, $ny);
imagecopyresized($nm, $im, 0, 0, 0, 0, $nx, $ny ,$ox, $oy);
imagejpeg($nm, $uploadfile, $q);
$_SESSION['ok'] = 'zagr';
header("Location: [url]http://1c-freelance.co/redact.php?blok=image[/url]");
}
elseif(empty($_FILES['fileField']['name'])){
// echo 'неполучили'.$_FILES;
// foreach($_FILES as $file => $value){
// echo $file.' = '.$value.'<br>';
// foreach( $value as $key => $val){
// echo ' '.$key.' = '.$val.'<br>';
// }
// }
$_SESSION['pustoi'] = 'error';
header("Location: [url]http://1c-freelance.co/redact.php?blok=image[/url]");
}
elseif($n == 5){
$_SESSION['errorFormat'] = 'error';
header("Location: [url]http://1c-freelance.co/redact.php?blok=image[/url]");
}
}
?>