You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

  1. <?php
  2. namespace dimti\Image;
  3. abstract class UploadHelper
  4. {
  5. /**
  6. * @param $proportion
  7. * @param $file_path
  8. * @return bool
  9. * @throws \ErrorException
  10. */
  11. public static function imageCompareAspectRatio($proportion, $file_path)
  12. {
  13. if (!(file_exists($file_path) && is_readable($file_path) && is_file($file_path))) {
  14. throw new \ErrorException('Unable to read file "' . $file_path . '".');
  15. }
  16. if ($imagesize = getimagesize($file_path)) {
  17. $proprtion_parts = explode('x', $proportion);
  18. if ($proprtion_parts[0] / $proprtion_parts[1] === $imagesize[0] / $imagesize[1]) {
  19. return true;
  20. }
  21. }
  22. return false;
  23. }
  24. /**
  25. * @param $size
  26. * @param $file_path
  27. * @return bool
  28. * @throws \ErrorException
  29. */
  30. public static function imageCompareSize($size, $file_path)
  31. {
  32. if (!(file_exists($file_path) && is_readable($file_path) && is_file($file_path))) {
  33. throw new \ErrorException('Unable to read file "' . $file_path . '".');
  34. }
  35. if ($imagesize = getimagesize($file_path)) {
  36. $size_parts = explode('x', $size);
  37. if ($imagesize[0] == $size_parts[0] && $imagesize[1] == $size_parts[1]) {
  38. return true;
  39. }
  40. }
  41. return false;
  42. }
  43. /**
  44. * @param $size
  45. * @param $file_path
  46. * @return bool
  47. */
  48. public static function imageCheckMinSize($size, $file_path)
  49. {
  50. $imagesize = getimagesize($file_path);
  51. $size_parts = explode('x', $size);
  52. if ($imagesize[0] >= $size_parts[0] && $imagesize[1] >= $size_parts[1]) {
  53. return true;
  54. } else {
  55. return false;
  56. }
  57. }
  58. }