[PHP] Thumb ruotati

loois

Nuovo Utente
11 Giu 2017
14
1
3
26
Ho un problema con il caricamento delle foto, insommo se scatto una foto con verticale me la ruota automaticamente, pero per il resto funziona benissimo, qualcuno può aiutarmi ?

il problema lo riscontro principalmene sui thumb ovvero le anterprime, ovvero tutti i file salvati (nome file)t.png/jpg/gif
PHP:
<?php
   $dir_img = '../img/user_img/';
   header('Cache-control: max-age='.(60*60*24*365));
   header('Expires: '.gmdate(DATE_RFC1123,time()+60*60*24*365));
   if (isset($_GET['img']) AND file_exists($dir_img.$_GET['img'].".png")) {
       if (isset($_GET['t'])) {
           $type = exif_imagetype ($dir_img.$_GET['img'].".png");
           $thumb = $dir_img.$_GET['img']."t.png";
           $thumboriginal = $dir_img.$_GET['img']."t.png";
           
           if (!file_exists($thumb)) {
               if ($type==1) {
                   $im = $dir_img.$_GET['img'].".png";
                   list($width, $height) = getimagesize($im);
                   $im = imagecreatefromgif($im);
                   if ($width > $height) {
                     $y = 0;
                     $x = ($width - $height) / 2;
                     $smallestSide = $height;
                   } else {
                     $x = 0;
                     $y = ($height - $width) / 2;
                     $smallestSide = $width;
                   }
                   $thumbSize = 300;
                   $thumb = imagecreatetruecolor($thumbSize, $thumbSize);
                   imagecopyresampled($thumb, $im, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);
                   $dirsave = $dir_img.$_GET['img']."t.png";
                   imagegif($thumb, $dirsave);
               }
               elseif ($type==2) {
                   $im = $dir_img.$_GET['img'].".png";
                   list($width, $height) = getimagesize($im);
                   $im = imagecreatefromjpeg($im);
                   if ($width > $height) {
                     $y = 0;
                     $x = ($width - $height) / 2;
                     $smallestSide = $height;
                   } else {
                     $x = 0;
                     $y = ($height - $width) / 2;
                     $smallestSide = $width;
                   }
                   $thumbSize = 300;
                   $thumb = imagecreatetruecolor($thumbSize, $thumbSize);
                   imagecopyresampled($thumb, $im, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);
                   $dirsave = $dir_img.$_GET['img']."t.png";
                   imagejpeg($thumb, $dirsave);
               }
               elseif ($type==3) {
                   $im = $dir_img.$_GET['img'].".png";
                   list($width, $height) = getimagesize($im);
                   $im = imagecreatefrompng($im);
                   if ($width > $height) {
                     $y = 0;
                     $x = ($width - $height) / 2;
                     $smallestSide = $height;
                   } else {
                     $x = 0;
                     $y = ($height - $width) / 2;
                     $smallestSide = $width;
                   }
                   $thumbSize = 300;
                   $thumb = imagecreatetruecolor($thumbSize, $thumbSize);
                   imagecopyresampled($thumb, $im, 90, 90, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);
                   $dirsave = $dir_img.$_GET['img']."t.png";
                   imagepng($thumb, $dirsave);
               }
               else {
                   header("Content-Type: image/png");
                   header('Content-Disposition: inline; filename="error.png');
                   $im = @imagecreate(300, 300);
                   $background_color = imagecolorallocate($im, 235, 235, 235);
                   $text_color = imagecolorallocate($im, 255, 0, 0);
                   imagestring($im, 5, 20, 140,  "FILE IMMAGINE NON SUPPORTATO", $text_color);
                   imagepng($im);
                   imagedestroy($im);
               }
           }
           if ($type==1) {
                   header('Content-Type: image/gif');
                   header('Content-Disposition: inline; filename="thumb.gif');
                   echo file_get_contents($thumboriginal);
               }
               elseif($type==2) {
                   header('Content-Type: image/jpeg');
                   header('Content-Disposition: inline; filename="thumb.jpg');
                   echo file_get_contents($thumboriginal);
               }
               elseif($type==3) {
                   header('Content-Type: image/png');
                   header('Content-Disposition: inline; filename="thumb.png');
                   echo file_get_contents($thumboriginal);
               }
       }
       else {
           $type = exif_imagetype ($dir_img.$_GET['img'].".png");
           if ($type==1) {
               $im = $dir_img.$_GET['img'].".png";
               header('Content-Type: image/gif');
               header('Content-Disposition: inline; filename="SocialEdge.gif');
               echo file_get_contents($im);
           }
           elseif ($type==2) {
               $im = $dir_img.$_GET['img'].".png";
               header('Content-Type: image/jpeg');
               header('Content-Disposition: inline; filename="SocialEdge.jpg');
               echo file_get_contents($im);
           }
           elseif ($type==3) {
               $im = $dir_img.$_GET['img'].".png";
               header('Content-Type: image/png');
               header('Content-Disposition: inline; filename="SocialEdge.png');
               echo file_get_contents($im);
           }
           else {
               header("Content-Type: image/png");
               header('Content-Disposition: inline; filename="error.png');
               $im = @imagecreate(300, 300);
               $background_color = imagecolorallocate($im, 235, 235, 235);
               $text_color = imagecolorallocate($im, 255, 0, 0);
               imagestring($im, 5, 20, 140,  "FILE IMMAGINE NON SUPPORTATO", $text_color);
               imagepng($im);
               imagedestroy($im);
           }
       }   
   }
   
   $dir_img = '../img/profile_img/';
   if (isset($_GET['profiloimg'])) {
       if (file_exists($dir_img.$_GET['profiloimg'].".png")) {
           $type = exif_imagetype ($dir_img.$_GET['profiloimg'].".png");
           if ($type==1) {
               $im = $dir_img.$_GET['profiloimg'].".png";
               header('Content-Type: image/gif');
               header('Content-Disposition: inline; filename="profilo.gif');
               echo file_get_contents($im);
           }
           elseif ($type==2) {
               $im = $dir_img.$_GET['profiloimg'].".png";
               header('Content-Type: image/jpeg');
               header('Content-Disposition: inline; filename="profilo.jpg');
               echo file_get_contents($im);
           }
           elseif ($type==3) {
               $im = $dir_img.$_GET['profiloimg'].".png";
               header('Content-Type: image/png');
               header('Content-Disposition: inline; filename="profilo.png');
               echo file_get_contents($im);
           }
           else {
               header("Content-Type: image/png");
               header('Content-Disposition: inline; filename="error.png');
               $im = @imagecreate(300, 300);
               $background_color = imagecolorallocate($im, 235, 235, 235);
               $text_color = imagecolorallocate($im, 255, 0, 0);
               imagestring($im, 5, 20, 140,  "FILE IMMAGINE NON SUPPORTATO", $text_color);
               imagepng($im);
               imagedestroy($im);
           }
       }
       else {
           $im = $dir_img."default.png";
           header('Content-Type: image/png');
           header('Content-Disposition: inline; filename="profilo.png');
           echo file_get_contents($im);
       }
       
       
       
   }
?>
 
Discussioni simili
Autore Titolo Forum Risposte Data
F Cerco Hosting con VECCHIE versioni di php Hosting 0
Cosina Captcha php PHP 1
S passare un valore da un form a un file .php con metodo post PHP 4
N php msyql PHP 6
N php problemi a visualizzare video PHP 3
A menu a tendina php PHP 1
D protezione cartelle: blocco visualizzazione/scaricamento contenuto, ma abilitazione utilizzo dati da parte di file .php presenti sul sito Web Server 1
F Php date_diff PHP 1
K [PHP] Aggiungere caratteri ad una stringa in base alla lunghezza della stessa PHP 2
C Wp-admin a file php WordPress 5
Lino80 [Retribuito] Cerco programmatore php per modifica/inserimento funzione/valori da un plugin importer wordpress Offerte e Richieste di Lavoro e/o Collaborazione 0
csi Inviare file jpg in locale alla stampante con php PHP 0
M Passaggio variabili array php su un tasto jq PHP 3
E Php aggiornamento tabella PHP 9
G phpmailer e php 8.1 con estensione mysqli PHP 6
M Invio dati database via email php PHP 0
K [php] Problema con inner join PHP 4
K [php]form invio dati PHP 0
P Codifica caratteri speciali mysql php PHP 0
K [PHP] Problema con variabili concatenate. PHP 1
E Stampante termica escpos-php PHP 6
JeiMax Modifica codice php personalizzato PHP 2
G Come modificare un pdf in php PHP 1
U Link a doppio file PHP PHP 0
E PHP & jQuery PHP 8
N Passare array da php a javascript PHP 5
F Applicazione PHP/MySQL per prenotazioni: limitare il numero massimo di posti prenotabili PHP 20
L tipo boolean non funzionante su mariadb (mysql). E codice php 7.4. PHP 0
U PHP creare un file excel dopo ricerca nel DB PHP 0
M PHP/MySQL - Estrarre valori min e max di ogni gruppo PHP 5
F Php e fatturazione elettronica PHP 0
P lanciare script asp (o php) da jquery Javascript 1
Couting95 inserire dati da un file di testo in una tabella in php PHP 1
P Data scraping in PHP non funziona PHP 4
C Calcoli matematici in php PHP 5
F Scrivere dei dati in word con php PHP 0
D PHP leggere cartella di Windows PHP 1
I dominio aruba versione php server linux Domini 3
G Colorare menu select attraverso ricerca php PHP 0
L PHP motore di ricerca nel sito PHP 1
S PHP e Mysqli PHP 0
Y Stampare da php su un foglio A6 attraverso una stampante esterna PHP 1
M Visulizzare immagine con php PHP 8
G [PHP] Creare script di prenotazione con controllo disponibilità. PHP 7
G leggere file txt e stampare con php il contenuto a video PHP 7
F Ricreare struttura php+mysql su Xampp Apache 0
Z PHP.INI - STMP per invio email con PHP Server Dedicati e VPS 0
M Array associativi php su 2 campi mysql PHP 10
G Invio form con PHP PHP 3
T fatture con voci fattura in php PHP 0

Discussioni simili