CommonHelper.php 901 B

1234567891011121314151617181920212223242526
  1. <?php
  2. // app/Libraries/CommonHelper.php
  3. namespace App\Libraries;
  4. class CommonHelper
  5. {
  6. /*
  7. * $images 格式:['image.jpg','image2.jpg']
  8. * 返回显示的HTML
  9. */
  10. public static function displayImage($images,$size=150)
  11. {
  12. $html = '<div style="display: flex; flex-wrap: wrap; gap: 5px;">';
  13. foreach ($images as $image) {
  14. $html .= "<div style='flex: 1 0 150px; max-width: {$size}px; max-height: {$size}px; padding: 10px; border: 1px solid #ddd; border-radius: 5px; background-color: #f9f9f9; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); display: flex; align-items: center; justify-content: center;'>
  15. <img data-action='preview-img' src='" . asset('storage/' . $image) . "' style='max-width: 100%; max-height: 100%; object-fit: contain;'>
  16. </div>";
  17. }
  18. $html .= '</div>';
  19. return $html;
  20. }
  21. }