# Define your your image names, along with
# any thumbnails they might need, and their max width and heights.
####
my %Media = {
img_1 => {
# scale down the image to this size if needed
target_geometry => '200x200',
thumbs => [
{ name => 'img_1_thumb_1', w => 100, h => 100 },
{ name => 'img_1_thumb_2', w => 50 , h => 50 },
],
},
####
# A simple syntax if you just want some thumbnails
img_2 => [
{ name => 'img_2_thumb_1', w => 100, h => 100 },
],
# And a very simple syntax if you want to store the image untouched.
img_3 => [],
};
# Create the accessor. This could be done once in a super class
# and stored in a param variable.
my $media_srv = CGI::ImageDB->new(
media_url => 'http://localhost/com/images/media',
media_dir => '/home/user/www/images/media',
dbh => $dbh,
media_table => 'media', # defaults to 'media'
media_def => \%Media,
);
####
-- Note the MySQL specific syntax here
create table media (
media_id int AUTO_INCREMENT primary key not null,
mime_type character varying(64),
extension character varying(8), -- file extension
width integer,
height integer
)
####
img_1_id
img_1_thumb_1_id
####
my %Media = {
img_1 => [
{ name => 'img_1_thumb_1', w => 100, h => 100 },
{ name => 'img_1_thumb_2', w => 50 , h => 50 },
],
img_2 =< [
{ name => 'img_2_thumb_1', w => 100, h => 100 },
],
img_3 => [],
};
####
my ($add_to_valid,@rm_from_valid) = $media_srv->create_install_media($valid);
####
$valid = { %$valid, %$add_to_valid } if $add_to_valid;
map { delete $valid->{$_} } @$rm_from_valid;
####
img_id_1 => 23
####
img_1_info
####
my @deleted_field_ids = $img_srv->delete_checked_media;
####
img_1_id
####
my $field_id = $img_srv->delete_media('img_1');
####
img_1_id
####
my $tmpl_vars_ref = $media_srv->create_img_tmpl_vars($table,\%where,@prefixes);
####
my $tmpl_vars_ref = $media_srv->create_img_tmpl_vars('news',{ item_id => 23 },qw/img_1/);
####
{
img_1_id => 523,
img_1_width => 100,
img_1_height => 200,
img_1_url => 'http://localhost/images/media/523.jpg',
}
####
SELECT media_id as id,width,height,extension
FROM media, $table where (media_id = ${prefix}_id and (%where_clause_expanded here));