Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
1
Language: PHP
Posted by: Alveen Ray Castaneda
Added: Aug 11, 2019 5:50 PM
Views: 34
Tags: no tags
  1. <!-- -------------------------------------------- -->
  2. <!-- "ak_php_img_lib_1.0.php" -->
  3. <!-- -------------------------------------------- -->
  4.  
  5. <?php
  6. // Adam Khoury PHP Image Function Library 1.0
  7. // ----------------------- RESIZE FUNCTION -----------------------
  8. // Function for resizing any jpg, bmp, or png image files
  9. function ak_img_resize($target, $newcopy, $w, $h, $ext) {
  10.     list($w_orig, $h_orig) = getimagesize($target);
  11.     $scale_ratio = $w_orig / $h_orig;
  12.     if (($w / $h) > $scale_ratio) {
  13.            $w = $h * $scale_ratio;
  14.     } else {
  15.            $h = $w / $scale_ratio;
  16.     }
  17.     $img = "";
  18.     $ext = strtolower($ext);
  19.     if ($ext == "bmp"){
  20.     $img = imagecreatefromgif($target);
  21.     } else if($ext =="jpeg"){
  22.     $img = imagecreatefrompng($target);
  23.     } else {
  24.     $img = imagecreatefromjpeg($target);
  25.     }
  26.     $tci = imagecreatetruecolor($w, $h);
  27.     // imagecopyresampled(dst_img, src_img, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
  28.     imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig);
  29.     if ($ext == "bmp"){
  30.         imagegif($tci, $newcopy);
  31.     } else if($ext =="jpeg"){
  32.         imagepng($tci, $newcopy);
  33.     } else {
  34.         imagejpeg($tci, $newcopy, 84);
  35.     }
  36. }
  37. // ------------------ IMAGE CONVERT FUNCTION -------------------
  38. // Function for converting GIFs and PNGs to JPG upon upload
  39. function ak_img_convert_to_jpg($target, $newcopy, $ext) {
  40.     list($w_orig, $h_orig) = getimagesize($target);
  41.     $ext = strtolower($ext);
  42.     $img = "";
  43.     if ($ext == "jpeg"){
  44.         $img = imagecreatefromgif($target);
  45.     } else if($ext =="bmp"){
  46.         $img = imagecreatefrompng($target);
  47.     }
  48.     $tci = imagecreatetruecolor($w_orig, $h_orig);
  49.     imagecopyresampled($tci, $img, 0, 0, 0, 0, $w_orig, $h_orig, $w_orig, $h_orig);
  50.     imagejpeg($tci, $newcopy, 84);
  51. }
  52. ?>