Revision 113

Date:
2011/08/17 12:23:35
Author:
ahitrov
Revision Log:
Image generation and saving transfered to File.pm and Object.pm
Files:

Legend:

 
Added
 
Removed
 
Modified
  • utf8/core/comps/contenido/components/set_image.msn

     
    21 21
    22 22 if ($SETS->{$field}) {
    23 23
    24 my @preview = exists $prop->{'preview'} && ref $prop->{'preview'} eq 'ARRAY' ? @{$prop->{'preview'}} : exists $prop->{'preview'} && $prop->{'preview'} ? ($prop->{'preview'}) : ();
    25 my @crops = exists $prop->{'crop'} && ref $prop->{'crop'} eq 'ARRAY' ? @{$prop->{'crop'}} : exists $prop->{'crop'} && $prop->{'crop'} ? ($prop->{'crop'}) : ();
    26 my @shrinks = exists $prop->{'shrink'} && ref $prop->{'shrink'} eq 'ARRAY' ? @{$prop->{'shrink'}} : exists $prop->{'shrink'} && $prop->{'shrink'} ? ($prop->{'shrink'}) : ();
    27
    28 if (ref $IMAGE eq 'HASH' && exists $IMAGE->{mini} && ref $IMAGE->{mini} eq 'HASH') {
    29 foreach my $val ( values %{$IMAGE->{mini}} ) {
    30 if ( ref $val && exists $val->{filename} && $val->{filename} ) {
    31 Contenido::File::remove($val->{'filename'});
    32 }
    33 }
    34 }
    35
    36 my $filename = '/images/'.$object->get_file_name() || return;
    37 my $filename_tmp = $state->{'tmp_dir'}.'/'.join('_', split('/', $filename));
    38
    39 24 my $upload = $r->upload($field);
    40 25 if ($upload) {
    41 my $extension = $upload->filename() =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin';
    42 my $fh = $upload->fh();
    43 my $size = (stat $fh)[7];
    44
    45 my $fh_tmp = IO::File->new('>'.$filename_tmp.'.'.$extension) || die 'Can\'t open temporary file';
    46
    47 my $buffer;
    48
    49 sysread $fh, $buffer, $size;
    50 syswrite $fh_tmp, $buffer, $size;
    51
    52 undef $fh_tmp;
    53
    54 if (Contenido::File::store($filename.'.'.$extension, $filename_tmp.'.'.$extension)) {
    55 if (ref $IMAGE eq 'HASH' and $IMAGE->{'filename'}) {
    56 Contenido::File::remove($IMAGE->{'filename'});
    57 }
    58
    59 # hashref slice assigning - жжесть
    60 @{$IMAGE}{'filename', 'width', 'height'} = (
    61 $filename.'.'.$extension,
    62 Image::Size::imgsize($filename_tmp.'.'.$extension),
    63 );
    64 foreach my $suffix (@preview) {
    65
    66 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'\' -quality 80 '.$filename_tmp.'.'.$extension.' '.$filename_tmp.'.'.$suffix.'.'.$extension;
    67 my $result = `$c_line`;
    68
    69 if (length $result > 0) {
    70 warn 'Contenido Error: При вызове "'.$c_line.'" произошла ошибка "'.$result.'" ('.$@.")\n";
    71 return undef;
    72 }
    73 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
    74 $filename.'.'.$suffix.'.'.$extension,
    75 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$extension),
    76 );
    77 %{$IMAGE->{'resize'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
    78 Contenido::File::store($filename.'.'.$suffix.'.'.$extension, $filename_tmp.'.'.$suffix.'.'.$extension);
    79 unlink $filename_tmp.'.'.$suffix.'.'.$extension if -e $filename_tmp.'.'.$suffix.'.'.$extension;
    80 }
    81 if ( @preview ) {
    82 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$preview[0]}}{'filename', 'width', 'height'};
    83 @{$IMAGE->{'resize'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$preview[0]}}{'filename', 'width', 'height'};
    84 }
    85 26
    86 ########## CROPS
    87 foreach my $suffix (@crops) {
    88
    89 my $shave_string;
    90 my ($nwidth, $nheight) = $suffix =~ /(\d+)x(\d+)/i ? ($1, $2) : (0, 0);
    91 if ( ($IMAGE->{width} / $IMAGE->{height}) > ($nwidth / $nheight) ) {
    92 my $shave_pixels = (($IMAGE->{width} / $IMAGE->{height}) - ($nwidth / $nheight)) * $IMAGE->{height};
    93 $shave_string = ' -shave '.int($shave_pixels / 2).'x0';
    94 } elsif ( ($IMAGE->{height} / $IMAGE->{width}) > ($nheight / $nwidth) ) {
    95 my $shave_pixels = (($IMAGE->{height} / $IMAGE->{width}) - ($nheight / $nwidth)) * $IMAGE->{width};
    96 $shave_string = ' -shave 0x'.int($shave_pixels / 2);
    97 }
    98 if ( $shave_string ) {
    99 my $c_line = $state->{"convert_binary"}." $shave_string $filename_tmp.$extension $filename_tmp.shaved.$extension";
    100 my $result = `$c_line`;
    101 if (length $result > 0) {
    102 print "Contenido Error: При вызове '$c_line' произошла ошибка '$result' ($@)\n";
    103 }
    104 } else {
    105 my $c_line = "cp $filename_tmp.$extension $filename_tmp.shaved.$extension";
    106 my $result = `$c_line`;
    107 if (length $result > 0) {
    108 print "Contenido Error: При вызове '$c_line' произошла ошибка '$result' ($@)\n";
    109 }
    110 }
    27 my $IMG = $object->_store_image( $upload, attr => $prop->{attr} );
    111 28
    112 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'!\' -quality 80 '.$filename_tmp.'.shaved.'.$extension.' '.$filename_tmp.'.'.$suffix.'.'.$extension;
    113 my $result = `$c_line`;
    114
    115 if (length $result > 0) {
    116 warn 'Contenido Error: При вызове "'.$c_line.'" произошла ошибка "'.$result.'" ('.$@.")\n";
    117 return undef;
    118 }
    119 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
    120 $filename.'.'.$suffix.'.'.$extension,
    121 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$extension),
    122 );
    123 %{$IMAGE->{'crop'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
    124 Contenido::File::store($filename.'.'.$suffix.'.'.$extension, $filename_tmp.'.'.$suffix.'.'.$extension);
    125 unlink $filename_tmp.'.shaved.'.$extension if -e $filename_tmp.'.shaved.'.$extension;
    126 unlink $filename_tmp.'.'.$suffix.'.'.$extension if -e $filename_tmp.'.'.$suffix.'.'.$extension;
    127 }
    128 if ( @crops ) {
    129 if ( !exists $IMAGE->{'mini'}{'filename'} ) {
    130 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$crops[0]}}{'filename', 'width', 'height'};
    131 }
    132 @{$IMAGE->{'crop'}}{'filename', 'width', 'height'} = @{$IMAGE->{'crop'}{$crops[0]}}{'filename', 'width', 'height'};
    133 }
    29 if ( ref $IMG eq 'HASH' && exists $IMG->{filename} ) {
    30 $object->_delete_image( $default );
    31 %$IMAGE = %$IMG;
    32 }
    134 33
    135 ########## SHRINKS
    136 foreach my $suffix (@shrinks) {
    137
    138 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'!\' -quality 80 '.$filename_tmp.'.'.$extension.' '.$filename_tmp.'.'.$suffix.'.'.$extension;
    139 my $result = `$c_line`;
    140
    141 if (length $result > 0) {
    142 warn 'Contenido Error: При вызове "'.$c_line.'" произошла ошибка "'.$result.'" ('.$@.")\n";
    143 return undef;
    144 }
    145 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
    146 $filename.'.'.$suffix.'.'.$extension,
    147 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$extension),
    148 );
    149 %{$IMAGE->{'shrink'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
    150 Contenido::File::store($filename.'.'.$suffix.'.'.$extension, $filename_tmp.'.'.$suffix.'.'.$extension);
    151 unlink $filename_tmp.'.'.$suffix.'.'.$extension if -e $filename_tmp.'.'.$suffix.'.'.$extension;
    152 }
    153 if ( @shrinks && !exists $IMAGE->{'mini'}{'filename'} ) {
    154 if ( !exists $IMAGE->{'mini'}{'filename'} ) {
    155 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$shrinks[0]}}{'filename', 'width', 'height'};
    156 }
    157 @{$IMAGE->{'shrink'}}{'filename', 'width', 'height'} = @{$IMAGE->{'shrink'}{$shrinks[0]}}{'filename', 'width', 'height'};
    158 }
    159
    160
    161 }
    162
    163 unlink $filename_tmp.'.'.$extension if -e $filename_tmp.'.'.$extension;
    164 34 } else {
    165 warn 'ERROR in incoming POST form: "'.$field.' is not file upload (value: "'.$SETS->{$field}.'")';
    35 warn 'ERROR in incoming POST form: "'.$field.' is not file upload (value: "'.$SETS->{$field}.'")';
    166 36 }
    167 37 }
    168 38
     
    172 42
    173 43 foreach my $localfield (keys(%{ $SETS })) {
    174 44 if ($localfield =~ /$pattern/) {
    175 my $imagefield = $1;
    176 $IMAGE->{$imagefield} = $m->comp("/contenido/components/filter.msn", str => $SETS->{$localfield});
    45 my $imagefield = $1;
    46 $IMAGE->{$imagefield} = $m->comp("/contenido/components/filter.msn", str => $SETS->{$localfield});
    177 47 }
    178 48 }
    179 49
    180 50 return $IMAGE;
    51
    181 52 </%init>
  • utf8/core/comps/contenido/components/set_properties.msn

     
    34 34
    35 35 if ($SETS->{'_delete_image.'.$name} == 1)
    36 36 {
    37 my $IMAGE = eval ('my '.$object->{ $name });
    38 Contenido::File::remove($IMAGE->{'filename'});
    39 Contenido::File::remove($IMAGE->{'mini'}{'filename'});
    40 foreach my $key (keys %{$IMAGE->{'mini'}}) {
    41 if (ref $IMAGE->{'mini'}{$key} && ref $IMAGE->{'mini'}{$key} eq 'HASH' && $IMAGE->{'mini'}{$key}->{'filename'}) {
    42 Contenido::File::remove($IMAGE->{'mini'}{$key}->{'filename'}) if $IMAGE->{'mini'}{$key}->{'filename'} ne $IMAGE->{'mini'}{'filename'};
    43 }
    44 }
    45 $object->{$name} = '';
    37 my $IMAGE = $object->get_image( $name );
    38 $object->_delete_image( $IMAGE );
    39 $object->$name('');
    46 40 } else {
    47 my $IMAGE = undef;
    48 if (length($object->{ $name }) > 8)
    49 {
    50 $IMAGE = eval ('my '.$object->{ $name });
    51 if (ref($IMAGE) ne 'HASH') { $IMAGE = {} };
    41 my $IMAGE = $object->get_image( $name );
    42 $IMAGE = ref $IMAGE ? $IMAGE : {};
    43 $IMAGE = $m->comp('/contenido/components/set_image.msn', default=>$IMAGE, field=>$name, SETS=>$SETS, object=>$object, prop => $prop);
    44 if ( exists $IMAGE->{filename} ) {
    45 local $Data::Dumper::Indent = 0;
    46 $object->$name( Data::Dumper::Dumper($IMAGE) );
    52 47 }
    53 $IMAGE = $m->comp('/contenido/components/set_image.msn', default=>$IMAGE, field=>$name, SETS=>$SETS, object=>$object, prop => $prop);
    54 if (exists($IMAGE->{filename}))
    55 {
    56 local $Data::Dumper::Indent = 0;
    57 $object->{$name} = Data::Dumper::Dumper($IMAGE);
    58 }
    59 48 }
    60 49
    61 50 } elsif ($prop->{type} =~ /^images/) {
    62 51 # --------------------------------------------------------------------------------------
    63 52 # А вот это уже сложнее - составление блока из всех картинок...
    64 53
    65 my $IMAGES = {};
    66 if (length($object->{ $name }) > 10)
    67 {
    68 $IMAGES = eval ('my '.$object->{ $prop->{attr} });
    69 if (ref($IMAGES) ne 'HASH')
    70 {
    71 $IMAGES = {};
    72 $IMAGES->{maxnumber} = 0;
    73 };
    74 }
    54 my $IMAGES = $object->get_image( $name );
    55 if (ref($IMAGES) ne 'HASH') {
    56 $IMAGES = {};
    57 $IMAGES->{maxnumber} = 0;
    58 };
    75 59
    76 my $maxnumber_ = 0;
    77
    78 60 # Теперь надо просмотреть все аргументы - а вдруг это то, что нам нужно...
    79 61 foreach my $arg (keys(%{ $SETS }))
    80 62 {
    81 # Разбиваем все на части, отделяем...
    82 my ($partname,undef) = split(/\./,$arg);
    83 $partname =~ /^(.+)_(\d+)$/;
    84 my ($localname,$number) = ($1, $2);
    85 if ( ($localname eq $prop->{attr}) && ($number > 0) && ( $arg eq $localname.'_'.$number ))
    86 {
    63 # Разбиваем все на части, отделяем...
    64 my ($partname,undef) = split(/\./,$arg);
    65 $partname =~ /^(.+)_(\d+)$/;
    66 my ($localname,$number) = ($1, $2);
    67 if ( ($localname eq $prop->{attr}) && ($number > 0) && ( $arg eq $localname.'_'.$number )) {
    87 68 # Ура! Нашли элемент!
    88 69
    89 70 my $partname = $localname.'_'.$number;
    90 71
    91 if ($SETS->{'_delete_image.'.$partname} == 1)
    92 {
    93 Contenido::File::remove($IMAGES->{'image_'.$number}{"filename"});
    94 Contenido::File::remove($IMAGES->{'image_'.$number}{"mini"}{"filename"});
    95 foreach my $key (keys %{$IMAGES->{'image_'.$number}{'mini'}}) {
    96 if (ref $IMAGES->{'image_'.$number}{'mini'}{$key} && ref $IMAGES->{'image_'.$number}{'mini'}{$key} eq 'HASH' && $IMAGES->{'image_'.$number}{'mini'}{$key}->{'filename'}) {
    97 Contenido::File::remove($IMAGES->{'image_'.$number}{'mini'}{$key}->{'filename'}) if $IMAGES->{'image_'.$number}{'mini'}{$key}->{'filename'} ne $IMAGES->{'image_'.$number}{'mini'}{'filename'};
    98 }
    99 }
    100 delete $IMAGES->{'image_'.$number};
    101 }
    102 else
    103 {
    104 my $IMAGE = undef;
    105 if (exists($IMAGES->{'image_'.$number}))
    106 {
    107 $IMAGE = $IMAGES->{'image_'.$number};
    108 };
    72 if ($SETS->{'_delete_image.'.$partname} == 1) {
    73 $object->_delete_image( $IMAGES->{'image_'.$number} );
    74 delete $IMAGES->{'image_'.$number};
    75 } else {
    76 my $IMAGE = undef;
    77 if (exists($IMAGES->{'image_'.$number})) {
    78 $IMAGE = $IMAGES->{'image_'.$number};
    79 };
    109 80 $IMAGE = $m->comp('/contenido/components/set_image.msn', default=>$IMAGE, field=>$partname, SETS=>$SETS, object=>$object, prop => $prop);
    110 if (exists($IMAGE->{filename}))
    111 {
    112 local $Data::Dumper::Indent = 0;
    113 $IMAGE->{number} = $number;
    114 $IMAGES->{'image_'.$number} = $IMAGE;
    115 $IMAGES->{maxnumber} = $number if ($number > $IMAGES->{maxnumber});
    116 }
    117 }
    118 }
    81 if (exists($IMAGE->{filename})) {
    82 local $Data::Dumper::Indent = 0;
    83 $IMAGE->{number} = $number;
    84 $IMAGES->{'image_'.$number} = $IMAGE;
    85 $IMAGES->{maxnumber} = $number if ($number > $IMAGES->{maxnumber});
    86 }
    87 }
    88 }
    89 }
    119 90
    120 }
    121
    122 if ( scalar(keys(%{ $IMAGES })) > 0)
    123 {
    91 if ( scalar(keys(%{ $IMAGES })) > 0) {
    124 92 my $maxnumber = 0;
    125 93 for ( 1..100 ) {
    126 94 $maxnumber = $_ if exists $IMAGES->{"image_$_"} && $_ > $maxnumber;
    127 95 }
    128 96 $IMAGES->{maxnumber} = $maxnumber;
    129 local $Data::Dumper::Indent = 0;
    130 $object->{$name} = Data::Dumper::Dumper($IMAGES);
    131 }
    97 local $Data::Dumper::Indent = 0;
    98 $object->$name( Data::Dumper::Dumper($IMAGES) );
    99 }
    132 100
    133 101 } elsif ( $prop->{type} eq 'multimedia' ) {
    134 102 # --------------------------------------------------------------------------------------
  • utf8/core/lib/Contenido/File.pm

     
    112 112 if (not ref $input) {
    113 113 no strict "refs";
    114 114 $fh = &{"Contenido::File::Scheme::".uc(scheme($input))."::get_fh"}($input);
    115 } elsif ((ref $input eq "GLOB") or (ref $input eq 'Apache::Upload') or (ref $input eq 'IO::File')) {
    115 } elsif ( ref $input eq 'Apache::Upload' ) {
    116 $fh = $input->fh;
    117 } elsif ((ref $input eq "GLOB") or (ref $input eq 'IO::File')) {
    116 118 $fh = $input;
    117 119 } elsif (ref $input eq "SCALAR") {
    118 120 $fh = IO::Scalar->new($input);
     
    153 155 # return $dir;
    154 156 # }
    155 157
    158 sub store_image {
    159 my $input = shift;
    160 my (%opts) = @_;
    161 my $object = delete $opts{object} || return;
    162 my $attr = delete $opts{attr} || return;
    163
    164 my ($prop) = grep { $_->{attr} eq $attr } $object->structure;
    165 return unless ref $prop;
    166 my @preview = exists $prop->{'preview'} && ref $prop->{'preview'} eq 'ARRAY' ? @{$prop->{'preview'}} : exists $prop->{'preview'} && $prop->{'preview'} ? ($prop->{'preview'}) : ();
    167 my @crops = exists $prop->{'crop'} && ref $prop->{'crop'} eq 'ARRAY' ? @{$prop->{'crop'}} : exists $prop->{'crop'} && $prop->{'crop'} ? ($prop->{'crop'}) : ();
    168 my @shrinks = exists $prop->{'shrink'} && ref $prop->{'shrink'} eq 'ARRAY' ? @{$prop->{'shrink'}} : exists $prop->{'shrink'} && $prop->{'shrink'} ? ($prop->{'shrink'}) : ();
    169
    170 my $filename = '/images/'.$object->get_file_name() || return;
    171 my $filename_tmp = $state->{'tmp_dir'}.'/'.join('_', split('/', $filename));
    172
    173 my $fh = get_fh($input);
    174 return unless ref $fh;
    175
    176 my $size = (stat $fh)[7];
    177 my $ext;
    178 if ( $opts{filename} ) {
    179 $ext = $opts{filename} =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin';
    180 } elsif ( not ref $input ) {
    181 $ext = $input =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin';
    182 } elsif ( ref $input eq 'Apache::Upload' ) {
    183 $ext = $input->filename() =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin';
    184 }
    185 $ext ||= 'bin';
    186
    187 my $fh_tmp = IO::File->new('>'.$filename_tmp.'.'.$ext) || return;
    188 my $buffer;
    189
    190 sysread $fh, $buffer, $size;
    191 syswrite $fh_tmp, $buffer, $size;
    192
    193 undef $fh_tmp;
    194
    195 my $IMAGE;
    196 if ( store($filename.'.'.$ext, $filename_tmp.'.'.$ext) ) {
    197 $IMAGE = {};
    198 # hashref slice assigning - жжесть
    199 @{$IMAGE}{'filename', 'width', 'height'} = (
    200 $filename.'.'.$ext,
    201 Image::Size::imgsize($filename_tmp.'.'.$ext),
    202 );
    203
    204 foreach my $suffix (@preview) {
    205 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'\' -quality 80 '.$filename_tmp.'.'.$ext.' '.$filename_tmp.'.'.$suffix.'.'.$ext;
    206 my $result = `$c_line`;
    207
    208 if (length $result > 0) {
    209 warn 'Contenido Error: При вызове "'.$c_line.'" произошла ошибка "'.$result.'" ('.$@.")\n";
    210 return undef;
    211 }
    212 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
    213 $filename.'.'.$suffix.'.'.$ext,
    214 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$ext),
    215 );
    216 %{$IMAGE->{'resize'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
    217 store($filename.'.'.$suffix.'.'.$ext, $filename_tmp.'.'.$suffix.'.'.$ext);
    218 unlink $filename_tmp.'.'.$suffix.'.'.$ext if -e $filename_tmp.'.'.$suffix.'.'.$ext;
    219 }
    220 if ( @preview ) {
    221 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$preview[0]}}{'filename', 'width', 'height'};
    222 @{$IMAGE->{'resize'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$preview[0]}}{'filename', 'width', 'height'};
    223 }
    224
    225 ########## CROPS
    226 foreach my $suffix (@crops) {
    227
    228 my $shave_string;
    229 my ($nwidth, $nheight) = $suffix =~ /(\d+)x(\d+)/i ? ($1, $2) : (0, 0);
    230 if ( ($IMAGE->{width} / $IMAGE->{height}) > ($nwidth / $nheight) ) {
    231 my $shave_pixels = (($IMAGE->{width} / $IMAGE->{height}) - ($nwidth / $nheight)) * $IMAGE->{height};
    232 $shave_string = ' -shave '.int($shave_pixels / 2).'x0';
    233 } elsif ( ($IMAGE->{height} / $IMAGE->{width}) > ($nheight / $nwidth) ) {
    234 my $shave_pixels = (($IMAGE->{height} / $IMAGE->{width}) - ($nheight / $nwidth)) * $IMAGE->{width};
    235 $shave_string = ' -shave 0x'.int($shave_pixels / 2);
    236 }
    237 if ( $shave_string ) {
    238 my $c_line = $state->{"convert_binary"}." $shave_string $filename_tmp.$ext $filename_tmp.shaved.$ext";
    239 my $result = `$c_line`;
    240 if (length $result > 0) {
    241 print "Contenido Error: При вызове '$c_line' произошла ошибка '$result' ($@)\n";
    242 }
    243 } else {
    244 my $c_line = "cp $filename_tmp.$ext $filename_tmp.shaved.$ext";
    245 my $result = `$c_line`;
    246 if (length $result > 0) {
    247 print "Contenido Error: При вызове '$c_line' произошла ошибка '$result' ($@)\n";
    248 }
    249 }
    250
    251 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'!\' -quality 80 '.$filename_tmp.'.shaved.'.$ext.' '.$filename_tmp.'.'.$suffix.'.'.$ext;
    252 my $result = `$c_line`;
    253
    254 if (length $result > 0) {
    255 warn 'Contenido Error: При вызове "'.$c_line.'" произошла ошибка "'.$result.'" ('.$@.")\n";
    256 return undef;
    257 }
    258 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
    259 $filename.'.'.$suffix.'.'.$ext,
    260 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$ext),
    261 );
    262 %{$IMAGE->{'crop'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
    263 store($filename.'.'.$suffix.'.'.$ext, $filename_tmp.'.'.$suffix.'.'.$ext);
    264 unlink $filename_tmp.'.shaved.'.$ext if -e $filename_tmp.'.shaved.'.$ext;
    265 unlink $filename_tmp.'.'.$suffix.'.'.$ext if -e $filename_tmp.'.'.$suffix.'.'.$ext;
    266 }
    267 if ( @crops ) {
    268 if ( !exists $IMAGE->{'mini'}{'filename'} ) {
    269 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$crops[0]}}{'filename', 'width', 'height'};
    270 }
    271 @{$IMAGE->{'crop'}}{'filename', 'width', 'height'} = @{$IMAGE->{'crop'}{$crops[0]}}{'filename', 'width', 'height'};
    272 }
    273
    274
    275 ########## SHRINKS
    276 foreach my $suffix (@shrinks) {
    277
    278 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'!\' -quality 80 '.$filename_tmp.'.'.$ext.' '.$filename_tmp.'.'.$suffix.'.'.$ext;
    279 my $result = `$c_line`;
    280
    281 if (length $result > 0) {
    282 warn 'Contenido Error: При вызове "'.$c_line.'" произошла ошибка "'.$result.'" ('.$@.")\n";
    283 return undef;
    284 }
    285 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
    286 $filename.'.'.$suffix.'.'.$ext,
    287 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$ext),
    288 );
    289 %{$IMAGE->{'shrink'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
    290 store($filename.'.'.$suffix.'.'.$ext, $filename_tmp.'.'.$suffix.'.'.$ext);
    291 unlink $filename_tmp.'.'.$suffix.'.'.$ext if -e $filename_tmp.'.'.$suffix.'.'.$ext;
    292 }
    293 if ( @shrinks && !exists $IMAGE->{'mini'}{'filename'} ) {
    294 if ( !exists $IMAGE->{'mini'}{'filename'} ) {
    295 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$shrinks[0]}}{'filename', 'width', 'height'};
    296 }
    297 @{$IMAGE->{'shrink'}}{'filename', 'width', 'height'} = @{$IMAGE->{'shrink'}{$shrinks[0]}}{'filename', 'width', 'height'};
    298 }
    299
    300 unlink $filename_tmp.'.'.$ext if -e $filename_tmp.'.'.$ext;
    301 }
    302
    303 return $IMAGE;
    304 }
    305
    306 sub remove_image {
    307 my $IMAGE = shift;
    308
    309 if ( ref $IMAGE eq 'HASH' && exists $IMAGE->{filename} ) {
    310 remove($IMAGE->{'filename'}) || return;
    311 }
    312 if ( ref $IMAGE && exists $IMAGE->{mini} && ref $IMAGE->{mini} eq 'HASH' ) {
    313 foreach my $val ( values %{$IMAGE->{mini}} ) {
    314 if ( ref $val && exists $val->{filename} && $val->{filename} ) {
    315 remove($val->{'filename'}) || return;
    316 }
    317 }
    318 }
    319 1;
    320 }
    321
    322
    156 323 1;
  • utf8/core/lib/Contenido/Object.pm

     
    18 18
    19 19 use Utils;
    20 20 use Contenido::Globals;
    21 use Contenido::File;
    21 22 use Data::Dumper;
    22 23
    23 24 use DBD::Pg;
     
    1130 1131 return $_[0]->keeper->state->memcached_object_expire;
    1131 1132 }
    1132 1133
    1134 # ----------------------------------------------------------------------------
    1135 # Метод _image_store() генерит сохраняет графику, привязанную к полю image или images
    1136 #
    1137 # Формат использования:
    1138 # $document->_image_store( INPUT, field => 'fieldname' )
    1139 # ----------------------------------------------------------------------------
    1140 sub _store_image {
    1141 my $self = shift;
    1142 do { $log->error("Метод delete() можно вызывать только у объектов, но не классов"); die } unless ref($self);
    1143
    1144 my $input = shift;
    1145 my (%opts) = @_;
    1146
    1147 return Contenido::File::store_image( $input, object => $self, attr => $opts{attr} );
    1148 }
    1149
    1150 sub _delete_image {
    1151 my $self = shift;
    1152 my $IMAGE = shift;
    1153
    1154 return Contenido::File::remove_image( $IMAGE );
    1155 }
    1156
    1133 1157 1;
    1134 1158
  • utf8/core/lib/Contenido/Parser.pm

     
    55 55 return $self;
    56 56 }
    57 57 }
    58 } elsif ((ref $input eq "GLOB") or (ref $input eq 'Apache::Upload') or (ref $input eq 'IO::File')) {
    58 } elsif ( ref $input eq 'Apache::Upload' ) {
    59 $fh = $input->fh;
    60 } elsif ((ref $input eq "GLOB") or (ref $input eq 'IO::File')) {
    59 61 $fh = $input;
    60 62 } elsif (ref $input eq "SCALAR") {
    61 63 $fh = IO::Scalar->new($input);