[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: как связать два скрипта
leonw
Здравствуйте! первое что я делаю это загружаю картинки так:
<form action="" method="post" enctype="multipart/form-data">
<input
type="file" name="file1" id="0.jpg">
<input
type="file" name="file2" id="1.jpg">
<input
type="file" name="file3" id="2.jpg">
<input
type="file" name="file4" id="3.jpg">
<input
type="submit" name="ok">
</form>

$dir='upload/';
$dir2='image/';
$i="0";
if(count($_POST)>0){
foreach($_FILES as $k=>$f) {
if (!$_FILES[$k]['error']) {$_FILES[$k]['error']==0
if (is_uploaded_file($_FILES[$k]['tmp_name']))
{
if (move_uploaded_file($_FILES[$k]['tmp_name'], $dir.$i++.'.jpg' ))
{
echo 'Файл: '.$_FILES[$k]['name'].' загружен.<br />';

и того получается: 0.jpg 1.jpg 2.jpg - я видел часто такой скрипт спрашивают, вот он.
а теперь как мне связать его с другим скриптом который уменьшает картинку:
можно таким: а)

запуск функции
$tmp_name = 'upload/0.jpg';
$new_name = 'upload/images/0'; //без расширения
$resolution_width = '200';
$resolution_height = '300';
$max_size = '10';
$message = images_size($tmp_name, $new_name, $resolution_width, $resolution_height, $max_size);

function images_size($tmp_name, $new_name, $resolution_width, $resolution_height, $max_size)
{
$image_size = filesize($tmp_name);
$image_size = floor($image_size / '10485760') ;
if($image_size <= $max_size) {

$params = getimagesize($tmp_name) ;
//проверяем ширину и высоту, нужно ли обрезание
if($params['0'] > $resolution_width || $params['1'] > $resolution_height) {

switch ($params['2']) {
case 1: $old_img = imagecreatefromgif($tmp_name); break;
case 2: $old_img = imagecreatefromjpeg($tmp_name); break;
case 3: $old_img = imagecreatefrompng($tmp_name); break;
case 6: $old_img = imagecreatefromwbmp($tmp_name); break;
}
if($params['0'] > $params['1']) {
$size = $params['0'] ;
$resolution = $resolution_width;
}
else {
$size = $params['1'] ;
$resolution = $resolution_height;
}
$new_width = floor($params['0'] * $resolution / $size) ;
$new_height = floor($params['1'] * $resolution / $size) ;
//создаём новое изображение
$new_img = imagecreatetruecolor($new_width, $new_height) ;
imagecopyresampled ($new_img, $old_img, 0, 0, 0, 0, $new_width, $new_height, $params['0'], $params['1']) ;

switch ($params['2']) {
case 1: $type = '.gif'; break;
case 2: $type = '.jpg'; break;
case 3: $type = '.png'; break;
case 6: $type = '.bmp'; break;
}
$new_name = "$new_name$type" ;
switch ($type) {
case '.gif': imagegif($new_img, $new_name); break;
case '.jpg': imagejpeg($new_img, $new_name, 100); break;
case '.bmp': imagejpeg($new_img, $new_name, 100); break;
case '.png': imagepng($new_img, $new_name); break;
}
$message = ('<font class="message">Изображение добавлено</font><br>') ;
imagedestroy($old_img);
}

else {
switch ($params['2']) {
case 1: $type = '.gif'; break;
case 2: $type = '.jpg'; break;
case 3: $type = '.png'; break;
case 6: $type = '.bmp'; break;
}
$new_name = "$new_name$type" ;
copy($tmp_name, $new_name);
$message = ('<font class="message">Изображение добавлено</font><br>') ;
}
}

else $errors = ('<font class="error">Слишком большой размер</font><br>') ;
return($message);
return($errors);
}

можно таким
Б)
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);
}
}

$file_input=0;
$file_output=$dir.$dir2.$i;
$w_o="100";
$h_o="100";
resize($file_input, $file_output, $w_o, $h_o, $percent = false);
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.