membuat thumnnail upload php

             <?php             // membuat ukuran file upload dengan fungsi define             define("MAX_SIZE", 800);              // membuat ukuran width dan height menjadi 200             define("HEIGHT", 200);             define("WIDTH", 200);              // membuat function thumbnail image             function thumb($img_name, $filename, $new_w, $new_h){              $ext = getExtension($img_name);              if(!strcmp("jpg",$ext) or !strcmp("jpeg",$ext)){               $src_img = imagecreatefromjpeg($img_name);              }              if (!strcmp("png",$ext)) {               $src_img = imagecreatefrompng($img_name);              }               //membuat dimensi dari image              $src_w = imagesx($src_img);              $src_h = imagesy($src_img);               //membuat dimensi untuk thumbnail image              $ratio1 = $src_w/$new_w;              $ratio2 = $src_h/$new_h;              if ($ratio1 > $ratio2) {               $dst_w = $new_w;               $dst_h = $src_w/$ratio1;              }else{               $dst_h = $new_h;               $dst_w = $src_h/$ratio2;              }               // menbuat image dengan dimensi baru              $dst_img = imagecreatetruecolor($dst_w,$dst_h);              imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);               if(!strcmp("png",$filename))               imagepng($dst_img, $filename);              else               imagejpeg($dst_img, $filename);               imagedestroy($dst_img);              imagedestroy($src_img);             }              function getExtension($str){              $i = strrpos($str, ".");              if(!$i){               return "";              }              $l = strlen($str) - $i;              $ext = substr($str,$i+1, $l);              return $ext;             }              ?>

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source