Salta al contenuto
  • CATEGORIES
  • La Community Connect.gt
  • Presentati alla Community
  • News Ufficiali da Connect.gt
  • Internet News
  • A Scuola Di
  • Digital Marketing
  • Intelligenza Artificiale
  • SEO & GEO
  • Web Marketing e Content
  • Google Analytics e Web Analytics
  • Google Ads & Advertising
  • YouTube
  • TikTok, Instagram e altri Social
  • Google Adsense, Affiliazioni e Guadagno
  • E-Commerce
  • Coding e Sistemistica
  • Help Center: consigli per il tuo progetto
  • Hosting e Cloud
  • Coding
  • CMS & Piattaforme Self-Hosted
  • Annunci e Collaborazioni
  • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
  • Collaborazioni WEB e Lavoro: offro e cerco
  • Impresa, Fisco e Leggi
  • Consulenza Legale e Professioni Web
  • Consulenza Fiscale, Imprese, Startup e P.Iva
  • Gli Off Topic
  • PC, Smartphone e altri Hardware
  • Tutti i Software
  • GT Fetish Cafè
  • Discussioni
  • 0 Non letti 0
  • Recenti
  • Hashtag
  • Popolare
  • Utenti
  • Privacy
  • Termini e condizioni
  • © 2026 Search On Media Group S.r.l.
Collassa
Connect.gt
Il network Search On
Connect.gt WMF AI Festival Accademia Advanced SEO Tool AgentCy Social Media Strategies Search Tech
Registrati Accedi
Connect.gt
Stream Interest Categorie Hashtag
  1. La community italiana di SEO, marketing digitale e AI
  2. Categorie
  3. Coding e Sistemistica
  4. Coding
  5. [SCRIPT] Resize image mantenendo proporzioni

[SCRIPT] Resize image mantenendo proporzioni

Pianificato Fissato Bloccato Spostato Coding
9 Post 4 Autori 8.4k Visualizzazioni 1 Seguito
  • Da Vecchi a Nuovi
  • Da Nuovi a Vecchi
  • Più Voti
Rispondi
  • Risposta alla discussione
Effettua l'accesso per rispondere
Questa discussione è stata eliminata. Solo gli utenti con diritti di gestione possono vederla.
  • S
    S
    sovietiko
    scritto su ultima modifica di
    User Attivo 0
    #1
    [SCRIPT] Resize image mantenendo proporzioni

    Ciao a tutti,

    mi dite cosa sbaglio in questo script ?

    list($ihwidth,$ihheight) = explode('x',$grandezza);
    //IMPOSTO UN MASSIMALE PER LE IMMAGINI
    $altezzamassima = "270";
    $larghezzamassima = "240";
    
    if($ihwidth > $larghezzamassima && $ihheight <= $altezzamassima) {
    $ihwidthprovvisorio = $ihwidth - $larghezzamassima;
    $ihwidth1 = $ihwidth - $ihwidthprovvisorio;
    
    $prendimolapercentualetolta = ($ihwidthprovvisorio/$ihwidth)*100;
    $ihheightprovv =($ihheight * $prendimolapercentualetolta)/100;
    $ihheight1 = round($ihheight - $ihheightprovv);
    }
    
    if($ihheight > $altezzamassima && $ihwidth <= $larghezzamassima) {
    $ihheightprovvisorio = $ihheight - $altezzamassima;
    $ihheight1 = $ihheight - $ihheightprovvisorio;
    
    $prendimolapercentualetolta2 = ($ihheightprovvisorio/$ihwidth)*100;
    $ihwidthprovv =($ihwidth * $prendimolapercentualetolta2)/100;
    $ihwidth1 = round($ihwidth - $ihwidthprovv);
    
    }
    
    if($ihheight > $altezzamassima && $ihwidth > $larghezzamassima) {
    $ihwidthprovvisorio = $ihwidth - $larghezzamassima;
    $ihheightprovvisorio = $ihheight - $altezzamassima;
    
    if($ihwidthprovvisorio >= $ihheightprovvisorio) {
    $ihwidthprovvisorio = $ihwidth - $larghezzamassima;
    $ihwidth1 = $ihwidth - $ihwidthprovvisorio;
    $prendimolapercentualetolta = ($ihwidthprovvisorio/$ihwidth)*100;
    $ihheightprovv =($ihheight * $prendimolapercentualetolta)/100;
    $ihheight1 = round($ihheight - $ihheightprovv);
    
    }
    
    else if($ihwidthprovvisorio < $ihheightprovvisorio){
    $ihheightprovvisorio = $ihheight - $altezzamassima;
    $ihheight1 = $ihheight - $ihheightprovvisorio;
    $prendimolapercentualetolta2 = ($ihheightprovvisorio/$ihwidth)*100;
    $ihwidthprovv =($ihwidth * $prendimolapercentualetolta2)/100;
    $ihwidth1 = round($ihwidth - $ihwidthprovv);
    }
    
    }
    else if($ihwidth <= $larghezzamassima && $ihheight <= $altezzamassima) {
    $ihwidth1 = $ihwidth;
    $ihheight1 = $ihheight;
    }
    

    Io vorrei solo ricreare l'immagine senza perdere il ratio..

    Avete idee?

    1 Risposta Ultima Risposta
    Miglior risposta 0
    0
    • S
      S
      sovietiko
      scritto su ultima modifica di
      User Attivo 0
      #2

      Se a qualcuno dovesse servire, ho ottimizzato lo script:

      list($ihwidth,$ihheight) = explode('x',$grandezza);
      //IMPOSTO UN MASSIMALE PER LE IMMAGINI
      $am = "270";
      $lm = "240";
      if($ihwidth > $lm or $ihheight > $am) {
      $eliminarel = $ihwidth - $lm;
      $eliminarea = $ihheight - $am;
      if (($elimnarel - $eliminarea) > ($eliminarea - $eliminarel)) { $perc = ($eliminarel*100)/$ihwidth;
      $ihw = round(($ihwidth/100)*$perc);
      $ihwidth1 = $ihwidth-$ihw;
      $ihh = round(($ihheight/100)*$perc);
      $ihheight1 = $ihheight - $ihh;
      }
      else if (($elimnarel - $eliminarea) < ($eliminarea - $eliminarel)) { $perc = ($eliminarea*100)/$ihheight;
      $ihw = round(($ihwidth/100)*$perc);
      $ihwidth1 = $ihwidth-$ihw;
      $ihh = round(($ihheight/100)*$perc);
      $ihheight1 = $ihheight - $ihh;
      }
      }
      else {
      $ihwidth1 = $ihwidth;
      $ihheight1 = $ihheight;
      }
      

      Funziona alla perfezione dato che calcola le %.

      Saluti.

      1 Risposta Ultima Risposta
      Miglior risposta 0
      0
      • S
        S
        sovietiko
        scritto su ultima modifica di
        User Attivo 0
        #3

        C'erano 2 errori, questo è perfetto:

        //IMPOSTO UN MASSIMALE PER LE IMMAGINI
        $am = "150";
        $lm = "150";
        
        if($ihwidth > $lm or $ihheight > $am) {
        $eliminarel = $ihwidth - $lm;
        $eliminarea = $ihheight - $am;
        if ($eliminarel >= $eliminarea)  { $perc = round(($eliminarel*100)/$ihwidth);
        $ihw = round(($ihwidth/100)*$perc);
        $ihwidth1 = $ihwidth-$ihw;
        $ihh = round(($ihheight/100)*$perc);
        $ihheight1 = $ihheight - $ihh;
        }
        else if ($eliminarel < $eliminarea) { $perc = round(($eliminarea*100)/$ihheight);
        $ihw = round(($ihwidth/100)*$perc);
        $ihwidth1 = $ihwidth-$ihw;
        $ihh = round(($ihheight/100)*$perc);
        $ihheight1 = $ihheight - $ihh;
        }
        }
        else {
        $ihwidth1 = $ihwidth;
        $ihheight1 = $ihheight;
        }
        
        1 Risposta Ultima Risposta
        Miglior risposta 0
        0
        • samyornS
          samyornS
          samyorn
          Consiglio Direttivo
          scritto su ultima modifica di
          Super User 113
          #4

          Ciao Sovietiko,
          ottimo script, complimenti.
          Con il tuo permesso mi piacerebbe inserirlo nella sezione script utili. 🙂

          1 Risposta Ultima Risposta
          Miglior risposta 0
          0
          • S
            S
            sovietiko
            scritto su ultima modifica di
            User Attivo 0
            #5

            Certo! Spero sarà utile a tutti! 🙂

            1 Risposta Ultima Risposta
            Miglior risposta 0
            0
            • samyornS
              samyornS
              samyorn
              Consiglio Direttivo
              scritto su ultima modifica di
              Super User 113
              #6

              Fatto, grazie a nome della community. 😉

              1 Risposta Ultima Risposta
              Miglior risposta 0
              0
              • M
                M
                mad02
                scritto su ultima modifica di
                User 0
                #7

                Buongiorno a tutti....sono un neofita e vorrei sapere all'interno di quale file devo aggiungere il codice. Utilizzo lo script:
                'giorgiotave.it/forum/scripting-e-risorse-utili/95013-tutorial-come-caricare-un-immagine-su-database-mysql.html'

                Ringrazio e Buon Anno!
                Marco

                1 Risposta Ultima Risposta
                Miglior risposta 0
                0
                • I
                  I
                  ilgrizly
                  scritto su ultima modifica di
                  User Newbie 0
                  #8

                  Sovietiko

                  C'erano 2 errori, questo è perfetto:

                  //IMPOSTO UN MASSIMALE PER LE IMMAGINI
                  $am = "150";
                  $lm = "150";
                  
                  if($ihwidth > $lm or $ihheight > $am) {
                  $eliminarel = $ihwidth - $lm;
                  $eliminarea = $ihheight - $am;
                  if ($eliminarel >= $eliminarea)  { $perc = round(($eliminarel*100)/$ihwidth);
                  $ihw = round(($ihwidth/100)*$perc);
                  $ihwidth1 = $ihwidth-$ihw;
                  $ihh = round(($ihheight/100)*$perc);
                  $ihheight1 = $ihheight - $ihh;
                  }
                  else if ($eliminarel < $eliminarea) { $perc = round(($eliminarea*100)/$ihheight);
                  $ihw = round(($ihwidth/100)*$perc);
                  $ihwidth1 = $ihwidth-$ihw;
                  $ihh = round(($ihheight/100)*$perc);
                  $ihheight1 = $ihheight - $ihh;
                  }
                  }
                  else {
                  $ihwidth1 = $ihwidth;
                  $ihheight1 = $ihheight;
                  }
                  

                  e in questo script dove lo dovrei collocare ? /forum/scripting-e-risorse-utili/95013-tutorial-come-caricare-un-immagine-su-database-mysql.html
                  :():

                  1 Risposta Ultima Risposta
                  Miglior risposta 0
                  0
                  • S
                    S
                    sovietiko
                    scritto su ultima modifica di
                    User Attivo 0
                    #9

                    Ciao,

                    quello script è davvero di base per il caricamento delle immagini..
                    Dovresti prima recuperare le dimensioni magari in questo modo:

                    //recupero altezza e larghezza
                    
                    $imagesize = @getimagesize($nome_file_temporaneo);
                    $ihwidth= $imagesize[0];
                    $ihheight= $imagesize[1];
                    
                    //IMPOSTO UN MASSIMALE PER LE IMMAGINI
                    $am = "150";
                    $lm = "150";
                    
                    if($ihwidth > $lm or $ihheight > $am) {
                    $eliminarel = $ihwidth - $lm;
                    $eliminarea = $ihheight - $am;
                    if ($eliminarel >= $eliminarea)  { $perc = round(($eliminarel*100)/$ihwidth);
                    $ihw = round(($ihwidth/100)*$perc);
                    $ihwidth1 = $ihwidth-$ihw;
                    $ihh = round(($ihheight/100)*$perc);
                    $ihheight1 = $ihheight - $ihh;
                    }
                    else if ($eliminarel < $eliminarea) { $perc = round(($eliminarea*100)/$ihheight);
                    $ihw = round(($ihwidth/100)*$perc);
                    $ihwidth1 = $ihwidth-$ihw;
                    $ihh = round(($ihheight/100)*$perc);
                    $ihheight1 = $ihheight - $ihh;
                    }
                    }
                    else {
                    $ihwidth1 = $ihwidth;
                    $ihheight1 = $ihheight;
                    }  
                    
                    //se l'immagine sarà da ridimensionare, verrà ridimensionata grazie allo script che calcola le giuste variazioni
                    
                    $thumb2 = imagecreatetruecolor($ihwidth1, $ihheight1);
                    imagecopyresized($thumb2, $source, 0, 0, 0, 0, $ihwidth1, $ihheight1, $ihwidth, $ihheight);
                    $anteprima2 = "nomefoto";
                    imagejpeg($thumb2, "percorso della foto".$anteprima2, 75);
                    

                    Ovviamente lascio a te mettere i controlli ecc.. Il codice è vecchio, ma grosso modo è così che funziona.

                    Ciao,
                    M.

                    1 Risposta Ultima Risposta
                    Miglior risposta 0
                    0

                    Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.

                    Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.

                    Con il tuo contributo, questo post potrebbe essere ancora migliore 💗

                    Registrati Accedi
                    Rispondi
                    • Risposta alla discussione
                    Effettua l'accesso per rispondere
                    • Da Vecchi a Nuovi
                    • Da Nuovi a Vecchi
                    • Più Voti


                    • Accedi

                    • Non hai un account? Registrati

                    • Accedi o registrati per effettuare la ricerca.
                    • Primo post
                      Ultimo post
                    Home Accedi Registrati
                    Menu
                    • CATEGORIES
                    • La Community Connect.gt
                    • Presentati alla Community
                    • News Ufficiali da Connect.gt
                    • Internet News
                    • A Scuola Di
                    • Digital Marketing
                    • Intelligenza Artificiale
                    • SEO & GEO
                    • Web Marketing e Content
                    • Google Analytics e Web Analytics
                    • Google Ads & Advertising
                    • YouTube
                    • TikTok, Instagram e altri Social
                    • Google Adsense, Affiliazioni e Guadagno
                    • E-Commerce
                    • Coding e Sistemistica
                    • Help Center: consigli per il tuo progetto
                    • Hosting e Cloud
                    • Coding
                    • CMS & Piattaforme Self-Hosted
                    • Annunci e Collaborazioni
                    • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
                    • Collaborazioni WEB e Lavoro: offro e cerco
                    • Impresa, Fisco e Leggi
                    • Consulenza Legale e Professioni Web
                    • Consulenza Fiscale, Imprese, Startup e P.Iva
                    • Gli Off Topic
                    • PC, Smartphone e altri Hardware
                    • Tutti i Software
                    • GT Fetish Cafè
                    • Discussioni
                    • Non letti 0
                    • Recenti
                    • Hashtag
                    • Popolare
                    • Utenti
                    • Privacy
                    • Termini e condizioni
                    • © 2026 Search On Media Group S.r.l.