Guest User

Untitled

a guest
Jul 18th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. <?php
  2.  
  3. header('Content-Type: image/png');
  4.  
  5. $file = "/home/thomedy/Desktop/images/pic.png";
  6. class featured_designer_resize
  7. {
  8. public $old_height;
  9. public $old_width;
  10. public $old_image;
  11. private $old_image_path = array();
  12. public $image_canvas;
  13.  
  14. public $new_height;
  15. public $new_width;
  16. public $new_image;
  17. private $new_image_path = array();
  18.  
  19. public $img;
  20.  
  21. public $file_ext;
  22.  
  23. public $by_eight;
  24.  
  25.  
  26.  
  27. public function __construct($featured_designer) {
  28.  
  29. $this->by_eight = 8;
  30. $old_designer_query = 'select featured_name from {your_featured_designer} limit 0, 1';
  31.  
  32. // $old_designer . '_thumbs');
  33. // $old_designer_results = db_query($old_designer_query);
  34.  
  35. $old_designer = '';
  36.  
  37. /* while($row = db_fetch_array($old_designer_results)) {
  38. $old_designer = $row['featured_name'];
  39. }
  40. */
  41. if(is_dir($old_designer . '_thumbs')) {
  42.  
  43. //***** check for old designer thumbs and clear the old thumbs ****//
  44. chdir($old_designer . '_thumbs');
  45. foreach(glob('*') as $f) if (is_file($f)) unlink($f);
  46. chdir('..');
  47. rmdir($old_designer . '_thumbs');
  48.  
  49.  
  50. //***** create new designer directory for thumbs ****//
  51. mkdir($featured_designer . '_thumbs');
  52. }
  53. else {
  54.  
  55. //***** create new designer directory for thumbs ****//
  56. mkdir($featured_designer . '_thumbs');
  57. }
  58.  
  59. }
  60.  
  61. public function featured_designer_get_image_extension($file) {
  62.  
  63. //****** remove extension to check which image type *******//
  64. $this->file_ext = strrchr($file, '.');
  65. }
  66.  
  67. public function featured_designer_get_image_size($filename) {
  68. list($width, $height) = getimagesize($filename);
  69. $this->old_width = $width;
  70. $this->old_height = $height;
  71.  
  72. }
  73.  
  74. public function featured_designer_set_new_image_size() {
  75. $this->new_width = $this->old_width / $this->by_eight;
  76. $this->new_height = $this->old_height / $this->by_eight;
  77. }
  78.  
  79. public function featured_designer_create_both_images($file) {
  80. $this->old_image = imagecreatetruecolor(75, 100);
  81.  
  82. if ($this->file_ext == '.jpg' || $file_ext == 'jpeg') {
  83. $this->img = imagecreatefromjpeg($file);
  84. }
  85. else if ($this->file_ext == '.png') {
  86. $this->img = imagecreatefrompng($file);
  87. }
  88. else if ($this->file_ext == '.gif') {
  89. $this->img = imagecreatefrompng($file);
  90. }
  91. else {
  92. $this->img = FALSE;
  93. }
  94.  
  95.  
  96. }
  97.  
  98. public function featured_designer_create_image() {
  99.  
  100. imagecopyresampled($this->old_image, $this->img, 0, 0, 0, 0, 75, 100, $old_width, $old_height);
  101. }
  102.  
  103. public function featured_designer_output_image() {
  104. if ($this->file_ext == '.jpg' || $this->file_ext == 'jpeg') {
  105. return imagejpeg($this->old_image);
  106. }
  107. else if ($this->file_ext == '.png') {
  108. return imagepng($this->old_image);
  109. }
  110. else if ($this->file_ext == '.gif') {
  111. return imagegif($this->old_image);
  112. }
  113. else {
  114. return FALSE;
  115. }
  116.  
  117. }
  118.  
  119. public function featured_designer_image_destroy() {
  120. imagedestroy($this->old_image);
  121. }
  122. }
  123.  
  124.  
  125.  
  126. $test = new featured_designer_resize('me');
  127. $test -> featured_designer_get_image_extension('/home/thomedy/Desktop/images/pic.jpg');
  128. $test -> featured_designer_get_image_size('/home/thomedy/Desktop/images/pic.jpg');
  129. $test -> featured_designer_set_new_image_size();
  130. $test -> featured_designer_create_both_images('/home/thomedy/Desktop/images/pic.jpg');
  131. $test -> featured_designer_output_image('/home/thomedy/Desktop/images/pic.jpg');
  132. $test -> featured_designer_image_destroy();
  133. //var_dump($test);
  134. ?>
Add Comment
Please, Sign In to add comment