SHARE
TWEET

Untitled

a guest Jun 19th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //RECORTAR E IMPORTAR AS FOTOS NO FTP ****************************************
  2. foreach($_FILES as $key => $ft){
  3.     if($ft['tmp_name']!=''){
  4.         $pastafoto = $root.'imagens/usuarios/';
  5.         $photo_url = $ft['tmp_name'];
  6.         list($width, $height, $type, $attr) = getimagesize($photo_url);
  7.         $nomearquivo=$ft['name'];
  8.         if($key=='foto'){
  9.             $proporcao=1;
  10.             $tamanho='150';
  11.         }elseif($key=='capa'){
  12.             $tamanho='1060';
  13.             $proporcao=6.057142857142857;
  14.         }
  15.  
  16.         if(!is_dir($pastafoto.$usuario['id'])){
  17.             mkdir($pastafoto.$usuario['id'], 0755);
  18.         }
  19.         $dest = $pastafoto.$usuario['id'].'/' . $nomearquivo;
  20.         $source_image = $photo_url;
  21.         $nome=$nomearquivo;
  22.         $destination = $pastafoto.$usuario['id'].'/'.$local.'/'.$nome;
  23.         $tn_w = $tamanho;
  24.         $tn_h = ($tamanho * $proporcao);
  25.         $quality = 80;
  26.         $wmsource = '';
  27.         $success = image_handler($source_image,$destination,$tn_w,$tn_h,$quality,$wmsource);
  28.         $sql = "UPDATE ptp_usuarios SET {$key}='{$nome}' WHERE id = {$usuario['id']}";
  29.         $result = $db->prepare( $sql );
  30.         $result->execute();
  31.     }
  32. }
  33. //FUNÇÃO COPIA FOTO
  34. function image_handler($source_image,$destination,$tn_w = 100,$tn_h = 100,$quality = 100,$wmsource = false) {
  35.     $info = getimagesize($source_image);
  36.     $imgtype = image_type_to_mime_type($info[2]);
  37.     switch ($imgtype) {
  38.         case 'image/jpeg':
  39.         $source = imagecreatefromjpeg($source_image);
  40.         break;
  41.         case 'image/gif':
  42.         $source = imagecreatefromgif($source_image);
  43.         break;
  44.         case 'image/png':
  45.         $source = imagecreatefrompng($source_image);
  46.         break;
  47.         default:
  48.         die('Invalid image type.');
  49.     }
  50.     $src_w = imagesx($source);
  51.     $src_h = imagesy($source);
  52.     $src_ratio = $src_w/$src_h;
  53.     if ($tn_w/$tn_h > $src_ratio) {
  54.         $new_h = $tn_w/$src_ratio;
  55.         $new_w = $tn_w;
  56.     } else {
  57.         $new_w = $tn_h*$src_ratio;
  58.         $new_h = $tn_h;
  59.     }
  60.     $x_mid = $new_w/2;
  61.     $y_mid = $new_h/2;
  62.  
  63.     // Now actually apply the crop and resize!
  64.  
  65. //ESSA LINHA ABAIXO É A QUE FALA QUE DEU ERRO! ***********************************************
  66.  
  67.     $newpic = imagecreatetruecolor(round($new_w), round($new_h));
  68.     imagecopyresampled($newpic, $source, 0, 0, 0, 0, $new_w, $new_h, $src_w, $src_h);
  69.     $final = imagecreatetruecolor($tn_w, $tn_h);
  70.     imagecopyresampled($final, $newpic, 0, 0, ($x_mid-($tn_w/2)), ($y_mid-($tn_h/2)), $tn_w, $tn_h, $tn_w, $tn_h);
  71.                     // If a watermark source file is specified, get the information about the watermark as well. This is the same thing we did above for the source image.
  72.     if($wmsource) {
  73.         $info = getimagesize($wmsource);
  74.         $imgtype = image_type_to_mime_type($info[2]);
  75.         switch ($imgtype) {
  76.             case 'image/jpeg':
  77.             $watermark = imagecreatefromjpeg($wmsource);
  78.             break;
  79.             case 'image/gif':
  80.             $watermark = imagecreatefromgif($wmsource);
  81.             break;
  82.             case 'image/png':
  83.             $watermark = imagecreatefrompng($wmsource);
  84.             break;
  85.             default:
  86.             die('Invalid watermark type.');
  87.         }
  88.         // Determine the size of the watermark, because we're going to specify the placement from the top left corner of the watermark image, so the width and height of the watermark matter.
  89.         $wm_w = imagesx($watermark);
  90.         $wm_h = imagesy($watermark);
  91.                         // Now, figure out the values to place the watermark in the bottom right hand corner. You could set one or both of the variables to "0" to watermark the opposite corners, or do your own math to put it somewhere else.
  92.                         //$wm_x = $tn_w - $wm_w;
  93.                         //$wm_y = $tn_h - $wm_h;
  94.         $wm_x = ($tn_w / 2) - ($wm_w / 2);
  95.         $wm_y = ($tn_h / 2) - ($wm_h / 2);
  96.                         // Copy the watermark onto the original image
  97.                         // The last 4 arguments just mean to copy the entire watermark
  98.         imagecopy($final, $watermark, $wm_x, $wm_y, 0, 0, $tn_w, $tn_h);
  99.     }
  100.                     // Ok, save the output as a jpeg, to the specified destination path at the desired quality.
  101.                     // You could use imagepng or imagegif here if you wanted to output those file types instead.
  102.     if(Imagejpeg($final,$destination,$quality)) {
  103.     return true;
  104.     }
  105.                     // If something went wrong
  106.     return false;
  107. }
  108.      
  109. PHP: Fatal Error: Allowed Memory Size of 8388608 Bytes Exhausted - 8 MB
  110. PHP: Fatal Error: Allowed Memory Size of 16777216 Bytes Exhausted - 16 MB
  111. PHP: Fatal Error: Allowed Memory Size of 33554432 Bytes Exhausted - 32 MB
  112. PHP: Fatal Error: Allowed Memory Size of 67108864 Bytes Exhausted - 64 MB
  113. PHP: Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted - 128 MB
  114. PHP: Fatal Error: Allowed Memory Size of 268435456 Bytes Exhausted - 256 MB
  115. PHP: Fatal Error: Allowed Memory Size of 536870912 Bytes Exhausted - 512 MB
  116. PHP: Fatal Error: Allowed Memory Size of 1073741824 Bytes Exhausted - 1 GB
  117.      
  118. upload_max_filesize
  119. file_uploads
  120. upload_max_filesize
  121. max_file_uploads
  122. post_max_size
  123. max_input_time
  124.      
  125. <?php
  126.     ini_set('memory_limit', '1024M'); // no caso usando 1G
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top