Code maintenance for uploading images of original size

Asked

Viewed 55 times

1

I am maintaining a code that uses the function below to upload and resize the image:

    function uploadArquivo($file, $dir_file, $prefixo_nome, $thumb = false, $dir_thumb = array(), $sizes = array()) {

  $nome_imagem = $file['name'];
  preg_match('/\.(gif|png|jpg|jpeg|pdf|doc|docx|rtf|txt|xls|xlsx|ppt|pptx|cdr|mp3|wma|aac|ogg|ac3|wav|mp4|avi|rmvb|mkv|bmp|zip|rar|7z){1}$/i', $nome_imagem, $ext);
  $ext = strtolower($ext[1]);
  $nome_imagem_formatado = $prefixo_nome . "_" . date('YmdHis') . str_replace(".", "", substr((string)microtime(), 1, 8)) . "." . $ext;
  $caminho = $dir_file . $nome_imagem_formatado;
  move_uploaded_file($file['tmp_name'], $caminho);

  if ($thumb) {
    for($i = 0; $i < count($dir_thumb); $i++) {
      $caminho_thumb = $dir_file . $dir_thumb[$i] . $nome_imagem_formatado;
      $imagem_file = CroppedThumbnail($caminho, $sizes[$i][0], $sizes[$i][1], $ext);
      imagejpeg($imagem_file, $caminho_thumb, 100);
    }
    // apaga original depois de recortar tudo o que precisa
    deleteArquivo($caminho);
  }

Below, resizing the image to 1550 x 750px:

$this->setUrlImagem(uploadArquivo($_FILES["imagem"], 'uploads/', 'produto', true, array('produtos/'), array(array(1550,750))));

This is what I need to do:

  • Upload image with original size and move to folder "upload/products/original";
  • Resize to height 320px and height proportional to the original and move to "upload/products folder"
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.