Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 60566f88

Von Werner Hahn vor mehr als 6 Jahren hinzugefügt

  • ID 60566f88588ad476cfe20195ef91b4e2ff9586b6
  • Vorgänger 6dbfb166
  • Nachfolger 1cac5fc6

WebshopApi: ThumbnailCreator

Unterschiede anzeigen:

SL/Controller/Helper/ThumbnailCreator.pm
15 15
our @ISA      = qw(Exporter);
16 16
our @EXPORT   = qw(file_create_thumbnail file_update_thumbnail file_probe_type file_probe_image_type file_update_type_and_dimensions);
17 17

  
18
# TODO PDFs and others like odt,txt,...
19 18
our %supported_mime_types = (
20 19
  'image/gif'  => { extension => 'gif', convert_to_png => 1, },
21 20
  'image/png'  => { extension => 'png' },
......
24 23
);
25 24

  
26 25
sub file_create_thumbnail {
27
  my ($self) = @_;
28
  croak "No picture set yet" if !$self->file_content;
29

  
30
  my $image            = GD::Image->new($self->file_content);
26
  my ($thumb) = @_;
27
  croak "No picture set yet" if !$thumb->{content};
28
  my $image            = GD::Image->new($thumb->{content});
31 29
  my ($width, $height) = $image->getBounds;
32 30
  my $max_dim          = 64;
33 31
  my $curr_max         = max $width, $height, 1;
......
38 36

  
39 37
  $thumbnail->copyResized($image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
40 38

  
41
  $self->thumbnail_img_content($thumbnail->png);
42
  $self->thumbnail_img_content_type('image/png');
43
  $self->thumbnail_img_width($new_width);
44
  $self->thumbnail_img_height($new_height);
45
  return 1;
39
  $thumb->{thumbnail_img_content} = $thumbnail->png;
40
  $thumb->{thumbnail_img_content_type} = "image/png";
41
  $thumb->{thumbnail_img_width} = $new_width;
42
  $thumb->{thumbnail_img_height} = $new_height;
43
  return $thumb;
46 44

  
47 45
}
48 46

  
......
66 64
}
67 65

  
68 66
sub file_probe_type {
69
  my ($self) = @_;
70

  
71
  return (t8("No file uploaded yet")) if !$self->file_content;
72
  my $mime_type = File::MimeInfo::Magic::magic($self->file_content);
73

  
74
  my $info = Image::Info::image_info(\$self->{file_content});
67
  my ($content) = @_;
68
  return (t8("No file uploaded yet")) if !$content;
69
  my $info = Image::Info::image_info(\$content);
75 70
  if (!$info || $info->{error} || !$info->{file_media_type} || !$supported_mime_types{ $info->{file_media_type} }) {
76 71
    $::lxdebug->warn("Image::Info error: " . $info->{error}) if $info && $info->{error};
77 72
    return (t8('Unsupported image type (supported types: #1)', join(' ', sort keys %supported_mime_types)));
78 73
  }
79 74

  
80
  $self->file_content_type($info->{file_media_type});
81
  $self->files_img_width($info->{width});
82
  $self->files_img_height($info->{height});
83
  $self->files_mtime(DateTime->now_local);
75
  my $thumbnail;
76
  $thumbnail->{file_content_type} = $info->{file_media_type};
77
  $thumbnail->{file_image_width} = $info->{width};
78
  $thumbnail->{file_image_height} = $info->{height};
79
  $thumbnail->{content} = $content;
84 80

  
85
  $self->file_create_thumbnail;
81
  $thumbnail = &file_create_thumbnail($thumbnail);
86 82

  
87
  return ();
83
  return $thumbnail;
88 84
}
89 85

  
90 86
sub file_update_type_and_dimensions {

Auch abrufbar als: Unified diff