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.

43 lines
1.3 KiB

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