Uploading images with manipulation using WideImage

1

Good evening! I would like to upload a maximum of 5 images and at the same time manipulate them with the WideImage library. But with the code done so far, only the upload is working. I'm using the library for the first time, so I do not have so much experience ... I hope someone can help me. Thank you!

    $images = $_FILES['fotos'];
    $name = $images['name']; //Atribui uma array com os nomes dos arquivos à variável
    $tmp_name = $images['tmp_name']; //Atribui uma array com os nomes temporários dos arquivos à variável
    $allowedExts = array(".gif", ".jpeg", ".jpg", ".png"); //Extensões permitidas
    $data_dir = date("Y.m.d-H.i.s");
    mkdir("fotos_noticia/" . $data_dir, 0777);
    $dir = 'fotos_noticia/' . $data_dir . "/";
    $img = array();
    $i = 0;

    //------------------------------------------------------------------------------------
    for ($i = 0; $i < sizeof($tmp_name); $i++) {
        $ext = strtolower(substr($name[$i], -4));
        if (in_array($ext, $allowedExts) && sizeof($tmp_name) <= 5) { //Pergunta se a extensão do arquivo, está presente no array das extensões permitidas
            $new_name = $i . $ext;
            $img[$i] = $new_name;
            $image = \WideImage::load($tmp_name[$i]); //Carrega a imagem utilizando a WideImage
            $image = $image->resize(450, 300, 'outside'); //Redimensiona a imagem para 170 de largura e 180 de altura, mantendo sua proporção no máximo possível
            $image = $image->crop('center', 'center', 450, 300); //Corta a imagem do centro, forçando sua altura e largura
            move_uploaded_file($tmp_name[$i], $dir.$new_name);
    
asked by anonymous 12.05.2018 / 00:05

0 answers