createthumb

The Responsive Minimal createthumb function.

Description

createthumb( (string) $name, (string) $filename, $new_w, $new_h ); 

Parameters (4)

0. $name (string)
The name.
1. $filename (string)
The filename.
2. $new_w
The new w.
3. $new_h
The new h.

Usage

  1. if ( !function_exists( 'createthumb' ) ) { 
  2. require_once '/functions/slider_images.php'; 
  3.  
  4. // The name. 
  5. $name = ''; 
  6.  
  7. // The filename. 
  8. $filename = ''; 
  9.  
  10. // The new w. 
  11. $new_w = null; 
  12.  
  13. // The new h. 
  14. $new_h = null; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = createthumb($name, $filename, $new_w, $new_h); 
  18.  

Defined (1)

The function is defined in the following location(s).

/functions/slider_images.php  
  1. function createthumb($name, $filename, $new_w, $new_h) 
  2. $path_info=pathinfo($name); 
  3. switch($path_info['extension']) { 
  4. case'gif': 
  5. $src_img=imagecreatefromgif($name); 
  6. break; 
  7. case'jpg': 
  8. case'jpeg': 
  9. $src_img=imagecreatefromjpeg($name); 
  10. break; 
  11. case'png': 
  12. $src_img=imagecreatefrompng($name); 
  13. break; 
  14. $old_x=imageSX($src_img); 
  15. $old_y=imageSY($src_img); 
  16. $thumb_w=$new_w; 
  17. $thumb_h=$new_h;  
  18. $dst_img=ImageCreateTrueColor($thumb_w, $thumb_h); 
  19. switch($path_info['extension']) { 
  20. case'gif': 
  21. case'png': 
  22. // integer representation of the color black (rgb: 0, 0, 0) 
  23. // removing the black from the placeholder 
  24. imagecolortransparent($dst_img, imagecolorallocatealpha($dst_img, 0, 0, 0, 127)); 
  25. // turning off alpha blending (to ensure alpha channel information  
  26. // is preserved, rather than removed (blending with the rest of the  
  27. // image in the form of black)) 
  28. imagealphablending($dst_img, false); 
  29. // turning on alpha channel information saving (to ensure the full range  
  30. // of transparency dst_img preserved) 
  31. imagesavealpha($dst_img, true); 
  32. break; 
  33. imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);  
  34. switch($path_info['extension']) { 
  35. case'gif': 
  36. imagegif($dst_img, $filename); 
  37. break; 
  38. case'jpg': 
  39. case'jpeg': 
  40. imagejpeg($dst_img, $filename); 
  41. break; 
  42. case'png': 
  43. imagepng($dst_img, $filename);  
  44. break; 
  45. }  
  46. imagedestroy($dst_img);  
  47. imagedestroy($src_img);  
  48. }