-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Hi Bricolage folk,
Bit of a head scratcher this. I am trying to make thumbnails with the
following code:
<%args>
$for
$user
</%args>
<%perl>;
my ($suffix, $prefix, $width, $height) = ( '_thumb', 'Thumb for ', 200,
120 );
return unless($for->isa('Bric::Biz::Asset::Business::Media::Image'));
# no point in dealing with non-images
return unless(grep {$for->get_file_name =~ /$_$/} qw(jpg jpeg png gif));
# sometimes videos are images. who knew?
my $thumb = eval {
$for->find_or_create_alternate({
title_prefix => $prefix,
file_suffix => $suffix,
et_key_name => 'thumbnail',
relate => 1,
user => $user,
checkin => 1,
transformer => sub {
shift->scale( xpixels => $width )->crop( height => $height );
}
})
};
if($@) {
my $e = "Something went wrong. You definitely uploaded the related
media as a photograph, right?\nHere's the debug info: \n";
$burner->throw_error(ref $@ ? $e . $@->error : $e . $@);
}
$burner->blaze_another($thumb, $for->get_cover_date, 1) unless
$thumb->get_publish_status;
return $thumb unless $burner->get_mode == PUBLISH_MODE;
</%perl>
I call it from within a loop on a cover page (i.e. once per story).
Here's a truncated version of that:
% my $acount=0;
% foreach my $article ( @stories ) {
- -----------------8<---------------
% my $thumb = '';
% if (defined $media) {
% $thumb = $m->comp('/util/get_thumb.mc', for=>$media,
user=>Bric::App::Session::get_user_object());
% }
<div class="hentry">
% if ($thumb && $acount ) {
<div class="image-left">
<img src="<% $thumb->get_primary_uri %>" alt="<% $thumb->get_title
%>" />
</div>
% }
- -----------------8<---------------
When a thumbnail has previously been created (by another user) my
thumbnail code throws this error:
"The URI '/category/2013/06/24/the_image_thumb.jpg' is not unique."
Well, that is true enough, I suppose. There is indeed an element with
that URI already in existence. However, the way I read the docs:
"The first thing this method does is see if a likely alternate already
exists by looking for a media document in the same site, with the
appropriate URI (as formed by the current media document's category,
cover date, and file name as modified by the file_prefix and file_suffix
parameters), and based on the appropriate element type. If such a media
document is found, it is simply returned and no further actions are taken."
makes me think that if the URI was not unique, the already existing
thumb should be returned (and if it weren't unique, then the error about
its non-uniqueness is misleading).
Have I misunderstood what the doc is trying to say? And, if not, how can
I make find_or_create_alternate do the find_ bit of its job?
Cheers,
- --
Charlie Harvey
IT Manager
New Internationalist
t: +44 (0)1865 811402
f: +44 (0)1865 793152
w: http://www.newint.org/
k: http://ox4.li/gpgkey/
** Celebrating 40 years of doing the right thing: New Internationalist,
est. 1973**
*Amnesty Media Award winner 2012*
New Internationalist is an independent not-for-profit communications
cooperative. Our multi-award winning magazine, New Internationalist,
brings to life the people, the ideas and the action in the fight for
global justice.
New Internationalist Publications Ltd. is incorporated in England
under no.1005239. Registered Office:
New Internationalist, 55 Rectory Road, Oxford, OX4 1BW, UK
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQIcBAEBCgAGBQJRyG2BAAoJEPytMqUZaqlzRhgP/i+d1b8idzeTA+0AygRQVgYZ
mgnCtwolVAz3YZiAOuuYzyCO9N/HTReXpTCbs71DnOyAF2UPFq2UsIZSz1c8qP8I
9tDqn2NuZTVmyTmkN7ECKEk7srDZxky8gSxYmXnlBC7WoPGeyszs+wexJGylQyt6
IxDLWkv01Q46SqClmZD/oaf7ygIJanlPvdyT0pKWknVpRTgprKS+E1SVGauujXJv
+TKKgqCjkPeRBvunE8z2MUUfJPn/Cjidz99EpQeMvagFFuQaPjnJ2fP1eRsqqbbN
mwZre64GDM3lH/Nb3ag6K2pSoDaiMrET4OtoHOOnd9tJF2GUM3nX1PB5os2zgHJr
Pvue68PxWmNnFGgioKoyNcShUoWlgUQhZdNIvDG4HzplB9o+yBw3Pehsz1KH7tx2
4f2J1V+O2D2223YhDWgI0h2yJMt3kOmQFgMnD3MlRcPNmq4KQDDSY7qGE488UBnK
v0dEw5zujJNw/8jjoczlfZSj7N3LlxPD3XtSsL9l71rP9OPJz/Rc0tcTzBAc/YJW
U1KfUf/BcIZVieclCRO6+GUnVnYOhll1zPyKHdFfWgx7IFt2QbPxsV/3YPT5B/8+
J8dyaHe+LF5ltiAYEBXINveFrCEFtsv6n5KCg39oU0oddtlJdiN6L6mE2UJWET6Q
EM2Nbl/KWfTR01M24eKI
=sHYb
-----END PGP SIGNATURE-----
Hash: SHA512
Hi Bricolage folk,
Bit of a head scratcher this. I am trying to make thumbnails with the
following code:
<%args>
$for
$user
</%args>
<%perl>;
my ($suffix, $prefix, $width, $height) = ( '_thumb', 'Thumb for ', 200,
120 );
return unless($for->isa('Bric::Biz::Asset::Business::Media::Image'));
# no point in dealing with non-images
return unless(grep {$for->get_file_name =~ /$_$/} qw(jpg jpeg png gif));
# sometimes videos are images. who knew?
my $thumb = eval {
$for->find_or_create_alternate({
title_prefix => $prefix,
file_suffix => $suffix,
et_key_name => 'thumbnail',
relate => 1,
user => $user,
checkin => 1,
transformer => sub {
shift->scale( xpixels => $width )->crop( height => $height );
}
})
};
if($@) {
my $e = "Something went wrong. You definitely uploaded the related
media as a photograph, right?\nHere's the debug info: \n";
$burner->throw_error(ref $@ ? $e . $@->error : $e . $@);
}
$burner->blaze_another($thumb, $for->get_cover_date, 1) unless
$thumb->get_publish_status;
return $thumb unless $burner->get_mode == PUBLISH_MODE;
</%perl>
I call it from within a loop on a cover page (i.e. once per story).
Here's a truncated version of that:
% my $acount=0;
% foreach my $article ( @stories ) {
- -----------------8<---------------
% my $thumb = '';
% if (defined $media) {
% $thumb = $m->comp('/util/get_thumb.mc', for=>$media,
user=>Bric::App::Session::get_user_object());
% }
<div class="hentry">
% if ($thumb && $acount ) {
<div class="image-left">
<img src="<% $thumb->get_primary_uri %>" alt="<% $thumb->get_title
%>" />
</div>
% }
- -----------------8<---------------
When a thumbnail has previously been created (by another user) my
thumbnail code throws this error:
"The URI '/category/2013/06/24/the_image_thumb.jpg' is not unique."
Well, that is true enough, I suppose. There is indeed an element with
that URI already in existence. However, the way I read the docs:
"The first thing this method does is see if a likely alternate already
exists by looking for a media document in the same site, with the
appropriate URI (as formed by the current media document's category,
cover date, and file name as modified by the file_prefix and file_suffix
parameters), and based on the appropriate element type. If such a media
document is found, it is simply returned and no further actions are taken."
makes me think that if the URI was not unique, the already existing
thumb should be returned (and if it weren't unique, then the error about
its non-uniqueness is misleading).
Have I misunderstood what the doc is trying to say? And, if not, how can
I make find_or_create_alternate do the find_ bit of its job?
Cheers,
- --
Charlie Harvey
IT Manager
New Internationalist
t: +44 (0)1865 811402
f: +44 (0)1865 793152
w: http://www.newint.org/
k: http://ox4.li/gpgkey/
** Celebrating 40 years of doing the right thing: New Internationalist,
est. 1973**
*Amnesty Media Award winner 2012*
New Internationalist is an independent not-for-profit communications
cooperative. Our multi-award winning magazine, New Internationalist,
brings to life the people, the ideas and the action in the fight for
global justice.
New Internationalist Publications Ltd. is incorporated in England
under no.1005239. Registered Office:
New Internationalist, 55 Rectory Road, Oxford, OX4 1BW, UK
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQIcBAEBCgAGBQJRyG2BAAoJEPytMqUZaqlzRhgP/i+d1b8idzeTA+0AygRQVgYZ
mgnCtwolVAz3YZiAOuuYzyCO9N/HTReXpTCbs71DnOyAF2UPFq2UsIZSz1c8qP8I
9tDqn2NuZTVmyTmkN7ECKEk7srDZxky8gSxYmXnlBC7WoPGeyszs+wexJGylQyt6
IxDLWkv01Q46SqClmZD/oaf7ygIJanlPvdyT0pKWknVpRTgprKS+E1SVGauujXJv
+TKKgqCjkPeRBvunE8z2MUUfJPn/Cjidz99EpQeMvagFFuQaPjnJ2fP1eRsqqbbN
mwZre64GDM3lH/Nb3ag6K2pSoDaiMrET4OtoHOOnd9tJF2GUM3nX1PB5os2zgHJr
Pvue68PxWmNnFGgioKoyNcShUoWlgUQhZdNIvDG4HzplB9o+yBw3Pehsz1KH7tx2
4f2J1V+O2D2223YhDWgI0h2yJMt3kOmQFgMnD3MlRcPNmq4KQDDSY7qGE488UBnK
v0dEw5zujJNw/8jjoczlfZSj7N3LlxPD3XtSsL9l71rP9OPJz/Rc0tcTzBAc/YJW
U1KfUf/BcIZVieclCRO6+GUnVnYOhll1zPyKHdFfWgx7IFt2QbPxsV/3YPT5B/8+
J8dyaHe+LF5ltiAYEBXINveFrCEFtsv6n5KCg39oU0oddtlJdiN6L6mE2UJWET6Q
EM2Nbl/KWfTR01M24eKI
=sHYb
-----END PGP SIGNATURE-----