PHP
0
Вклад в тег
function upload_image()
{
if(isset($_FILES['user_image']))
{
// Count total files
$countfiles = count($_FILES['user_image']['name']);
for($i=0;$i<$countfiles;$i++){
$extension = explode('.', $_FILES['user_image']['name'][$i]);
$new_name = rand() . '.' . $extension[1];
$destination = '../portfolio/upload/' . $new_name;
$thumbDestination = '../portfolio/upload/thumb/' . $new_name;
move_uploaded_file($_FILES['user_image']['tmp_name'][$i], $destination);
resize($destination, $thumbDestination, 300);
}
return $new_name;
}
}
function resize($source, $destination, $width){
$image = new Imagick($source);
// Получаем соотношение сторон для пропорционального ресайза.
$d = $image->getImageGeometry();
$w = $d['width'];
$h = $d['height'];
$aspectratio = $h / $w;
// Ресайзим и сохраняем.
$image->resizeImage($width, $width*$aspectratio, Imagick::FILTER_LANCZOS, 1);
$image->writeImage($destination);
$image->destroy();
}