Advertisement
juliarnasution

fungsi_thumbnail.php

Feb 28th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1. <?php
  2. // Upload gambar untuk berita, album, galeri foto, banner
  3. function UploadFoto($fupload_name, $folder, $ukuran){
  4.   // File gambar yang di upload
  5.   $file_upload = $folder . $fupload_name;
  6.  
  7.   // Simpan gambar dalam ukuran aslinya
  8.   move_uploaded_file($_FILES["fupload"]["tmp_name"], $file_upload);
  9.  
  10.   // Identitas file asli
  11.   $gbr_asli = imagecreatefromjpeg($file_upload);
  12.   $lebar    = imageSX($gbr_asli);
  13.   $tinggi   = imageSY($gbr_asli);
  14.  
  15.   // Simpan dalam versi thumbnail
  16.   $thumb_lebar  = $ukuran;
  17.   $thumb_tinggi = ($thumb_lebar/$lebar) * $tinggi;
  18.  
  19.   // Proses perubahan dimensi ukuran
  20.   $gbr_thumb = imagecreatetruecolor($thumb_lebar,$thumb_tinggi);
  21.   imagecopyresampled($gbr_thumb, $gbr_asli, 0, 0, 0, 0, $thumb_lebar, $thumb_tinggi, $lebar, $tinggi);
  22.  
  23.   // Simpan gambar thumbnail
  24.   imagejpeg($gbr_thumb,$folder . "small_" . $fupload_name);
  25.  
  26.   // Hapus gambar di memori komputer
  27.   imagedestroy($gbr_asli);
  28.   imagedestroy($gbr_thumb);
  29. }
  30. function UploadFotouser($fupload_name, $folder, $ukuran){
  31.   // File gambar yang di upload
  32.   $file_upload = $folder . $fupload_name;
  33.  
  34.   // Simpan gambar dalam ukuran aslinya
  35.   move_uploaded_file($_FILES["ffoto"]["tmp_name"], $file_upload);
  36.   // Identitas file asli
  37.   $gbr_asli = imagecreatefromjpeg($file_upload);
  38.   $lebar    = imageSX($gbr_asli);
  39.   $tinggi   = imageSY($gbr_asli);
  40.  
  41.   // Simpan dalam versi thumbnail
  42.   $thumb_lebar  = $ukuran;
  43.   $thumb_tinggi = ($thumb_lebar/$lebar) * $tinggi;
  44.  
  45.   // Proses perubahan dimensi ukuran
  46.   $gbr_thumb = imagecreatetruecolor($thumb_lebar,$thumb_tinggi);
  47.   imagecopyresampled($gbr_thumb, $gbr_asli, 0, 0, 0, 0, $thumb_lebar, $thumb_tinggi, $lebar, $tinggi);
  48.  
  49.   // Simpan gambar thumbnail
  50.   imagejpeg($gbr_thumb,$folder . "small_" . $fupload_name);
  51.  
  52.   // Hapus gambar di memori komputer
  53.   imagedestroy($gbr_asli);
  54.   imagedestroy($gbr_thumb);
  55. }
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement