|
List Info
Thread: Thumbnail.mc question
|
|
| Thumbnail.mc question |

|
2008-02-25 23:33:05 |
I've been using the /util/thumbnail.mc for ages now (and
love it) but,
on one site, I've found that it suddenly stopped publishing
the
thumbnails. They're created, but when I publish the story,
they don't
publish with it. They used to -- not sure what's changed?
Nothing in
the log to indicate an error. Code in question is below.
The odd thing is, it's there in the preview. But, when I
publish, I
get a broken image link on the published story. I can find
the
thumbnail and publish it, but that kinda defeats the whole
purpose.
Thoughts?
<%args>
$image
$key_name => $image->get_element_key_name
$file_prefix => 'thumb-'
$file_suffix => ''
$title_prefix => 'Thumbnail for '
$title_suffix => ''
</%args>
<%once>;
my $ET_CLASS = $Bric::Biz::ElementType::VERSION
? 'Bric::Biz::ElementType'
: 'Bric::Biz::AssetType';
</%once>
<%perl>;
my $melem = $image->get_element;
# Try to find an existing thumbnail image.
if (my $thumb = $melem->get_related_media) {
return $thumb;
}
# We don't need the URI but calling it before _thumb_file
will ensure
that a
# thumbnail is created if it doesn't already exist.
$image->thumbnail_uri;
# XXX Yeah yeah, I know I shouldn't call a private
method...
my $path = $image->_thumb_file;
my $image_fn = $image->get_file_name;
my $thumb_fn =
"$file_prefix$image_fn$file_suffix";
(my $uri =
URI::Escape::uri_unescape($image->get_uri))
=~ s{Q$image_fnE$}{$thumb_fn};
# Make sure that the thumbnail file exists.
$burner->throw_error(
qq{Thumbnail file "$path" does not exist; is
USE_THUMBNAILS
enabled?}
) unless -f $path;
# Look up the thumbnail element type.
my $et = $ET_CLASS->lookup({ key_name => $key_name })
or $burner->throw_error(qq{Could not find the
"$key_name" element
type});
# Create the thumbnail media document.
my $thumb = Bric::Biz::Asset::Business::Media->new({
priority => $image->get_priority,
title => $title_prefix .
$image->get_title . $title_suffix,
description => $title_prefix .
$image->get_description .
$title_suffix,
site_id => $image->get_site_id,
source__id => $image->get_source__id,
media_type_id =>
$image->get_media_type->get_id,
category__id => $image->get_category__id,
element_type => $et,
user__id => Bric::App::Session::get_user_id,
});
$thumb->set_cover_date($image-
>get_cover_date(Bric::Config::ISO_8601_FORMAT));
$thumb->save;
# Add the thumbnail image file to the media document.
open my $thumb_fh, '<', $path or die "Cannot open
'$path': $!n";
$thumb->upload_file($thumb_fh => $thumb_fn);
close $thumb_fh;
# Check in the thumbnail document.
$thumb->checkin;
$thumb->save;
# Add the thumbnail to the media document and return it.
$melem->set_related_media($thumb);
$melem->save;
return $thumb;
</%perl>
--
Phillip Smith,
Simplifier of Technology
Community Bandwidth
http://www.community
bandwidth.ca
|
|
| Re: Thumbnail.mc question |

|
2008-02-25 23:58:45 |
Hmmm... I occasionally get this error:
An error occurred while processing your request:
Unable to execute SQL statement
DBD::Pg::st execute failed: ERROR: insert or update on table
"media_instance" violates foreign key constraint
"fk_usr__media_instance" DETAIL: Key
(usr__id)=(1025) is not present
in table "usr". [for Statement "INSERT INTO
media_instance (id, name,
description, media__id, usr__id, version, media_type__id,
primary_oc__id, category__id, file_size, file_name,
location, uri,
cover_date, note, checked_out) VALUES
(NEXTVAL
('seq_media_instance'), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?)"
with ParamValues: 2='Created by /util/alt_media.mc',
3='1092',
4='1025', 5='1', 6='60', 7='1', 8='1035'] at
/home/user/bricolage/lib/
Bric/Util/DBI.pm line 1083, <GEN1174> line 3259.
Stack: [/home/user/
bricolage/lib/Bric/Util/DBI.pm:1083]
[/home/user/bricolage/lib/Bric/
Biz/Asset/Business/Media.pm:2157]
[/home/user/bricolage/lib/Bric/Biz/
Asset/Business/Media.pm:1879]
[/home/user/bricolage/data/burn/comp/
oc_1024/util/alt_media.mc:289]
[/usr/lib/perl5/vendor_perl/5.8.4/HTML/
Mason/Component.pm:135]
[/home/user/bricolage/data/burn/comp/oc_1/
blog_post.mc:64]
[/usr/lib/perl5/vendor_perl/5.8.4/HTML/Mason/
Component.pm:135]
[/home/user/bricolage/lib/Bric/Util/Burner/Mason.pm:
557]
[/home/user/bricolage/data/burn/comp/oc_1/autohandler:36]
[/usr/
lib/perl5/vendor_perl/5.8.4/HTML/Mason/Component.pm:135]
Please report this error to your administrator.
It's odd, because I'm user 1024, and there is no user 1025,
but there
is a 1026, 1027, etc.
And, sometimes, if I change the image, I get:
Story "Test post" saved and checked in to
"Publish".
"Test post" published to Default Site.
"3140961.jpg" published to Default Site.
But, the thumbnail doesn't get published. I also noticed
that the
thumbnail isn't being related to the parent media document
any more,
which I'm pretty sure it was at one point...?
Totally confusing. Points to investigate?
Phillip.
On 26-Feb-08, at 12:33 AM, Phillip Smith wrote:
>
> I've been using the /util/thumbnail.mc for ages now
(and love it)
> but, on one site, I've found that it suddenly stopped
publishing the
> thumbnails. They're created, but when I publish the
story, they
> don't publish with it. They used to -- not sure what's
changed?
> Nothing in the log to indicate an error. Code in
question is below.
>
> The odd thing is, it's there in the preview. But, when
I publish, I
> get a broken image link on the published story. I can
find the
> thumbnail and publish it, but that kinda defeats the
whole purpose.
> Thoughts?
>
> <%args>
> $image
> $key_name => $image->get_element_key_name
> $file_prefix => 'thumb-'
> $file_suffix => ''
> $title_prefix => 'Thumbnail for '
> $title_suffix => ''
> </%args>
> <%once>;
> my $ET_CLASS = $Bric::Biz::ElementType::VERSION
> ? 'Bric::Biz::ElementType'
> : 'Bric::Biz::AssetType';
> </%once>
> <%perl>;
> my $melem = $image->get_element;
>
> # Try to find an existing thumbnail image.
> if (my $thumb = $melem->get_related_media) {
> return $thumb;
> }
>
> # We don't need the URI but calling it before
_thumb_file will
> ensure that a
> # thumbnail is created if it doesn't already exist.
> $image->thumbnail_uri;
>
> # XXX Yeah yeah, I know I shouldn't call a private
method...
> my $path = $image->_thumb_file;
> my $image_fn = $image->get_file_name;
> my $thumb_fn =
"$file_prefix$image_fn$file_suffix";
> (my $uri =
URI::Escape::uri_unescape($image->get_uri))
> =~ s{Q$image_fnE$}{$thumb_fn};
>
> # Make sure that the thumbnail file exists.
> $burner->throw_error(
> qq{Thumbnail file "$path" does not exist;
is USE_THUMBNAILS
> enabled?}
> ) unless -f $path;
>
> # Look up the thumbnail element type.
> my $et = $ET_CLASS->lookup({ key_name =>
$key_name })
> or $burner->throw_error(qq{Could not find the
"$key_name" element
> type});
>
> # Create the thumbnail media document.
> my $thumb =
Bric::Biz::Asset::Business::Media->new({
> priority => $image->get_priority,
> title => $title_prefix .
$image->get_title . $title_suffix,
> description => $title_prefix .
$image->get_description .
> $title_suffix,
> site_id => $image->get_site_id,
> source__id => $image->get_source__id,
> media_type_id =>
$image->get_media_type->get_id,
> category__id => $image->get_category__id,
> element_type => $et,
> user__id =>
Bric::App::Session::get_user_id,
> });
>
> $thumb->set_cover_date($image-
> >get_cover_date(Bric::Config::ISO_8601_FORMAT));
> $thumb->save;
>
> # Add the thumbnail image file to the media document.
> open my $thumb_fh, '<', $path or die "Cannot
open '$path': $!n";
> $thumb->upload_file($thumb_fh => $thumb_fn);
> close $thumb_fh;
>
> # Check in the thumbnail document.
> $thumb->checkin;
> $thumb->save;
>
> # Add the thumbnail to the media document and return
it.
> $melem->set_related_media($thumb);
> $melem->save;
> return $thumb;
> </%perl>
>
> --
> Phillip Smith,
> Simplifier of Technology
> Community Bandwidth
> http://www.community
bandwidth.ca
>
>
>
--
Phillip Smith,
Simplifier of Technology
Community Bandwidth
http://www.community
bandwidth.ca
|
|
| Re: Thumbnail.mc question |

|
2008-02-26 23:57:57 |
Just a quick follow-up on this: Any thoughts on how I could
force the
publish of the thumbnail image at the time of its creation?
Phillip.
On 26-Feb-08, at 12:33 AM, Phillip Smith wrote:
>
> I've been using the /util/thumbnail.mc for ages now
(and love it)
> but, on one site, I've found that it suddenly stopped
publishing the
> thumbnails. They're created, but when I publish the
story, they
> don't publish with it. They used to -- not sure what's
changed?
> Nothing in the log to indicate an error. Code in
question is below.
>
> The odd thing is, it's there in the preview. But, when
I publish, I
> get a broken image link on the published story. I can
find the
> thumbnail and publish it, but that kinda defeats the
whole purpose.
> Thoughts?
>
> <%args>
> $image
> $key_name => $image->get_element_key_name
> $file_prefix => 'thumb-'
> $file_suffix => ''
> $title_prefix => 'Thumbnail for '
> $title_suffix => ''
> </%args>
> <%once>;
> my $ET_CLASS = $Bric::Biz::ElementType::VERSION
> ? 'Bric::Biz::ElementType'
> : 'Bric::Biz::AssetType';
> </%once>
> <%perl>;
> my $melem = $image->get_element;
>
> # Try to find an existing thumbnail image.
> if (my $thumb = $melem->get_related_media) {
> return $thumb;
> }
>
> # We don't need the URI but calling it before
_thumb_file will
> ensure that a
> # thumbnail is created if it doesn't already exist.
> $image->thumbnail_uri;
>
> # XXX Yeah yeah, I know I shouldn't call a private
method...
> my $path = $image->_thumb_file;
> my $image_fn = $image->get_file_name;
> my $thumb_fn =
"$file_prefix$image_fn$file_suffix";
> (my $uri =
URI::Escape::uri_unescape($image->get_uri))
> =~ s{Q$image_fnE$}{$thumb_fn};
>
> # Make sure that the thumbnail file exists.
> $burner->throw_error(
> qq{Thumbnail file "$path" does not exist;
is USE_THUMBNAILS
> enabled?}
> ) unless -f $path;
>
> # Look up the thumbnail element type.
> my $et = $ET_CLASS->lookup({ key_name =>
$key_name })
> or $burner->throw_error(qq{Could not find the
"$key_name" element
> type});
>
> # Create the thumbnail media document.
> my $thumb =
Bric::Biz::Asset::Business::Media->new({
> priority => $image->get_priority,
> title => $title_prefix .
$image->get_title . $title_suffix,
> description => $title_prefix .
$image->get_description .
> $title_suffix,
> site_id => $image->get_site_id,
> source__id => $image->get_source__id,
> media_type_id =>
$image->get_media_type->get_id,
> category__id => $image->get_category__id,
> element_type => $et,
> user__id =>
Bric::App::Session::get_user_id,
> });
>
> $thumb->set_cover_date($image-
> >get_cover_date(Bric::Config::ISO_8601_FORMAT));
> $thumb->save;
>
> # Add the thumbnail image file to the media document.
> open my $thumb_fh, '<', $path or die "Cannot
open '$path': $!n";
> $thumb->upload_file($thumb_fh => $thumb_fn);
> close $thumb_fh;
>
> # Check in the thumbnail document.
> $thumb->checkin;
> $thumb->save;
>
> # Add the thumbnail to the media document and return
it.
> $melem->set_related_media($thumb);
> $melem->save;
> return $thumb;
> </%perl>
>
> --
> Phillip Smith,
> Simplifier of Technology
> Community Bandwidth
> http://www.community
bandwidth.ca
>
>
>
--
Phillip Smith,
Simplifier of Technology
Community Bandwidth
http://www.community
bandwidth.ca
|
|
| Re: Thumbnail.mc question |

|
2008-02-28 17:35:49 |
On Feb 26, 2008, at 21:57, Phillip Smith wrote:
> Just a quick follow-up on this: Any thoughts on how I
could force
> the publish of the thumbnail image at the time of its
creation?
You can preview on creation using AUTO_PREVIEW_MEDIA, but
not publish.
Best,
David
|
|
| Re: Thumbnail.mc question |

|
2008-02-29 08:20:23 |
Hi Phillip.
I've posted the current image_resize_and_relate.mc here. It
will
optionally publish thumbnails when they're created, based on
an argument
you can set when you call the template. (This has the effect
of
publishing the images when the story calling them into
existence is
previewed.)
The original reason for this was that we had Bricolage
publishing to one
front-end Sportsnet machine, which was rsyncing every minute
with
several other machines. Sometimes the front page would be
published and
rsynced onto on all the front-end machines before the story
itself
finished, and that would cause broken thumbnail images on
the home page
for a minute.
Doing it this way allowed us to be sure the images would all
be on the
production machines before the home page got there.
Not sure if this helps, but there you go.
Cheers,
Bret
On Wed, 2008-02-27 at 00:57 -0500, Phillip Smith wrote:
> Just a quick follow-up on this: Any thoughts on how I
could force the
> publish of the thumbnail image at the time of its
creation?
>
> Phillip.
>
> On 26-Feb-08, at 12:33 AM, Phillip Smith wrote:
>
> >
> > I've been using the /util/thumbnail.mc for ages
now (and love it)
> > but, on one site, I've found that it suddenly
stopped publishing the
> > thumbnails. They're created, but when I publish
the story, they
> > don't publish with it. They used to -- not sure
what's changed?
> > Nothing in the log to indicate an error. Code in
question is below.
> >
> > The odd thing is, it's there in the preview. But,
when I publish, I
> > get a broken image link on the published story. I
can find the
> > thumbnail and publish it, but that kinda defeats
the whole purpose.
> > Thoughts?
> >
> > <%args>
> > $image
> > $key_name =>
$image->get_element_key_name
> > $file_prefix => 'thumb-'
> > $file_suffix => ''
> > $title_prefix => 'Thumbnail for '
> > $title_suffix => ''
> > </%args>
> > <%once>;
> > my $ET_CLASS = $Bric::Biz::ElementType::VERSION
> > ? 'Bric::Biz::ElementType'
> > : 'Bric::Biz::AssetType';
> > </%once>
> > <%perl>;
> > my $melem = $image->get_element;
> >
> > # Try to find an existing thumbnail image.
> > if (my $thumb = $melem->get_related_media) {
> > return $thumb;
> > }
> >
> > # We don't need the URI but calling it before
_thumb_file will
> > ensure that a
> > # thumbnail is created if it doesn't already
exist.
> > $image->thumbnail_uri;
> >
> > # XXX Yeah yeah, I know I shouldn't call a private
method...
> > my $path = $image->_thumb_file;
> > my $image_fn = $image->get_file_name;
> > my $thumb_fn =
"$file_prefix$image_fn$file_suffix";
> > (my $uri =
URI::Escape::uri_unescape($image->get_uri))
> > =~ s{Q$image_fnE$}{$thumb_fn};
> >
> > # Make sure that the thumbnail file exists.
> > $burner->throw_error(
> > qq{Thumbnail file "$path" does not
exist; is USE_THUMBNAILS
> > enabled?}
> > ) unless -f $path;
> >
> > # Look up the thumbnail element type.
> > my $et = $ET_CLASS->lookup({ key_name =>
$key_name })
> > or $burner->throw_error(qq{Could not find
the "$key_name" element
> > type});
> >
> > # Create the thumbnail media document.
> > my $thumb =
Bric::Biz::Asset::Business::Media->new({
> > priority => $image->get_priority,
> > title => $title_prefix .
$image->get_title . $title_suffix,
> > description => $title_prefix .
$image->get_description .
> > $title_suffix,
> > site_id => $image->get_site_id,
> > source__id => $image->get_source__id,
> > media_type_id =>
$image->get_media_type->get_id,
> > category__id =>
$image->get_category__id,
> > element_type => $et,
> > user__id =>
Bric::App::Session::get_user_id,
> > });
> >
> > $thumb->set_cover_date($image-
> >
>get_cover_date(Bric::Config::ISO_8601_FORMAT));
> > $thumb->save;
> >
> > # Add the thumbnail image file to the media
document.
> > open my $thumb_fh, '<', $path or die
"Cannot open '$path': $!n";
> > $thumb->upload_file($thumb_fh =>
$thumb_fn);
> > close $thumb_fh;
> >
> > # Check in the thumbnail document.
> > $thumb->checkin;
> > $thumb->save;
> >
> > # Add the thumbnail to the media document and
return it.
> > $melem->set_related_media($thumb);
> > $melem->save;
> > return $thumb;
> > </%perl>
> >
> > --
> > Phillip Smith,
> > Simplifier of Technology
> > Community Bandwidth
> > http://www.community
bandwidth.ca
> >
> >
> >
>
> --
> Phillip Smith,
> Simplifier of Technology
> Community Bandwidth
> http://www.community
bandwidth.ca
>
>
>
>
--
Bret Dawson
Producer
Pectopah Productions Inc.
(416) 895-7635
bret pectopah.com
www.pectopah.com
|
|
| Re: Thumbnail.mc question |

|
2008-02-29 08:38:15 |
This time, with the template.
<%args>
%element_names_and_sizes
%needs_cropping
$publish_images_on_story_preview
$picture
$target_image_element_type
$media_workflow
$publish_desk
</%args>
<%perl>
use Bric::Util::Time qw(:all);
use Date::Format;
use DateTime;
my $date = time;
my $formatted_date = strfdate($date);
# $m->out($formatted_date . '<br>');
# $m->out('Today is: ' . DateTime->now(time_zone =>
'Canada/Eastern')->strftime("%Y/%m/%d") .
'<br>');
my ($picture_is_good, $format, $scolding, $user,
$new_media_document);
if (!$story->get_user__id) {
$user = Bric::App::Session->get_user_id;
} else {
$user = $story->get_user__id;
}
#pull out the media document inside the element and make
sure it's a picture
if ($picture->get_related_media) {
$scolding = $m->scomp('/util/image_check.mc',
pic => $picture->get_related_media
);
if ($scolding) {
$m->out('<strong>' . $scolding .
'</strong><br>');
} else {
$picture_is_good = 1;
$format = $burner->notes('ext');
$burner->notes( ext => '' );
}
}
if ($picture_is_good) {
my (%check_list, %safe_list);
#check for containers
foreach my $container_type(keys %element_names_and_sizes)
{
foreach my
$existing_container($picture->get_elements) {
if (($existing_container->get_key_name eq
$container_type) && (!$check_list{$container_type}))
{
#OK, we're working with this one
$check_list{$container_type} = 1;
$safe_list{$existing_container->get_id} = 1;
}
}
}
#kill any duplicate containers
foreach my $container_type(keys %element_names_and_sizes)
{
foreach my
$existing_container($picture->get_elements) {
if (($existing_container->get_key_name eq
$container_type) &&
(!$safe_list{$existing_container->get_id})) {
#OK, we're deleting this one
my killswitch;
$killswitch[0] = $existing_container;
$picture->delete_elements( killswitch);
$picture->save;
}
}
}
#create any missing containers
foreach my $container_type(keys %element_names_and_sizes)
{
if (!$check_list{$container_type}) {
my $required_container_type =
Bric::Biz::ElementType->lookup({ 'key_name' =>
$container_type });
$picture->add_container($required_container_type);
$picture->save;
}
}
#OK, we now have all the containers we need.
#Loop through them. If they already have pictures, leave
them alone.
#If they don't have pictures, create them and relate them.
foreach my
$working_container($picture->get_containers(keys
%element_names_and_sizes)) {
if ($working_container->get_related_media) {
my $thumbScolding =
$m->scomp('/util/image_check.mc',
pic => $working_container->get_related_media
);
if ($thumbScolding) {
#container has bad media file
$m->out('<strong>' . $thumbScolding .
'</strong><br>');
} else {
#container has good media file, so leave it alone
}
} else {
#container is empty, so create image and relate it to
container
my $target_element_type =
Bric::Biz::ElementType->lookup({key_name =>
$target_image_element_type});
my $media_document_title =
$picture->get_related_media->get_title . '-' .
$working_container->get_key_name;
my %target_initial_state = (
'user__id' => $user,
'active' => 1,
'priority' => $story->get_priority,
'title' =>
$picture->get_related_media->get_title . '-' .
$working_container->get_key_name,
'description' => '',
'workflow_id' => $media_workflow->get_id,
'element_type' => $target_element_type,
'site_id' => $story->get_site_id,
'source__id' =>
$picture->get_related_media->get_source__id,
'cover_date' => $formatted_date,
# 'media_type_id' =>
$picture->get_related_media->get_media_type->get_id
,
'category__id' =>
$picture->get_related_media->get_category__id
);
my $new_file_name =
$picture->get_related_media->get_file_name;
my $extension =
"_$element_names_and_sizes{$working_container->get_k
ey_name}.$format";
$new_file_name =~ s/....$/$extension/;
my $new_uri =
$picture->get_related_media->get_primary_category->
get_uri . DateTime->now(time_zone =>
'Canada/Eastern')->strftime("%Y/%m/%d/") .
$new_file_name;
#check if there is already an image with the same URI
in the Bricolage library.
#If there is, open that media document. Otherwise
create a new one.
# $m->out('Looking for an existing media document
with this uri:<br>' .
$picture->get_related_media->get_primary_category->
get_uri . time2str("%Y/%m/%d/", $date) .
$new_file_name . '<br>');
my existing_media_document =
Bric::Biz::Asset::Business::Media->list({
'uri' => $new_uri,
'active' => 1
});
if ($existing_media_document[0]) {
# $m->out('<br>Found existing one. URI is ' .
$existing_media_document[0]->get_primary_uri .
'<br>');
$new_media_document = $existing_media_document[0];
# $new_media_document->checkout({ user__id =>
$user });
} else {
$new_media_document =
Bric::Biz::Asset::Business::Media::Image->new(%target_in
itial_state);
$new_media_document->set_workflow_id($media_workflow->
get_id);
$new_media_document->save;
$publish_desk->accept({ asset =>
$new_media_document });
$publish_desk->save;
$new_media_document->checkin;
}
#Here we go, making the new image
my $temp_file = "/tmp/$new_file_name";
my $new_image = new Image::Magick;
$new_image->Read($picture->get_related_media->get_p
ath);
if ($needs_cropping{'height_aspect'}) {
# $m->out('<br><br>Going to crop!');
my $target_height =
int(($needs_cropping{'height_aspect'} *
$picture->get_related_media->get_value('width')) /
$needs_cropping{'width_aspect'});
$new_image->Crop( geometry =>
$picture->get_related_media->get_value('width')."
x$target_height+0+0" );
# } else {
# $m->out('<br><br>NOT going to
crop!');
}
$new_image->Thumbnail($element_names_and_sizes{$working_c
ontainer->get_key_name});
$new_image->Set(colorspace=>'RGB');
$new_image->Write($temp_file);
undef $new_image;
#now upload our new image
my $file_handler;
open ($file_handler, "<$temp_file");
$new_media_document->upload_file($file_handler,
$new_file_name,
$picture->get_related_media->get_media_type->get_na
me);
#no need to close filehandler because upload_file does
it automatically
#delete the temp image here
unlink ($temp_file);
#save and check in if required
$new_media_document->save;
if ($new_media_document->get_checked_out) {
# $publish_desk->checkin($new_media_document);
$new_media_document->checkin;
}
if ($publish_images_on_story_preview eq 'Yes') {
# $m->out('Got the go-ahead to publish images on
preview<br><br>');
unless ($new_media_document->get_publish_status)
{
# $m->out('Trying to publish "' .
$new_media_document->get_title . '".<br>');
$burner->publish_another($new_media_document,$picture->
;get_related_media->get_cover_date,1);
}
}
#relate the image to the container
$working_container->set_related_media($new_media_document
);
$working_container->save;
}
}
}
</%perl>
On Fri, 2008-02-29 at 09:20 -0500, Bret Dawson wrote:
> Hi Phillip.
>
> I've posted the current image_resize_and_relate.mc
here. It will
> optionally publish thumbnails when they're created,
based on an argument
> you can set when you call the template. (This has the
effect of
> publishing the images when the story calling them into
existence is
> previewed.)
>
> The original reason for this was that we had Bricolage
publishing to one
> front-end Sportsnet machine, which was rsyncing every
minute with
> several other machines. Sometimes the front page would
be published and
> rsynced onto on all the front-end machines before the
story itself
> finished, and that would cause broken thumbnail images
on the home page
> for a minute.
>
> Doing it this way allowed us to be sure the images
would all be on the
> production machines before the home page got there.
>
> Not sure if this helps, but there you go.
>
> Cheers,
>
> Bret
>
>
> On Wed, 2008-02-27 at 00:57 -0500, Phillip Smith
wrote:
> > Just a quick follow-up on this: Any thoughts on
how I could force the
> > publish of the thumbnail image at the time of its
creation?
> >
> > Phillip.
> >
> > On 26-Feb-08, at 12:33 AM, Phillip Smith wrote:
> >
> > >
> > > I've been using the /util/thumbnail.mc for
ages now (and love it)
> > > but, on one site, I've found that it suddenly
stopped publishing the
> > > thumbnails. They're created, but when I
publish the story, they
> > > don't publish with it. They used to -- not
sure what's changed?
> > > Nothing in the log to indicate an error. Code
in question is below.
> > >
> > > The odd thing is, it's there in the preview.
But, when I publish, I
> > > get a broken image link on the published
story. I can find the
> > > thumbnail and publish it, but that kinda
defeats the whole purpose.
> > > Thoughts?
> > >
> > > <%args>
> > > $image
> > > $key_name =>
$image->get_element_key_name
> > > $file_prefix => 'thumb-'
> > > $file_suffix => ''
> > > $title_prefix => 'Thumbnail for '
> > > $title_suffix => ''
> > > </%args>
> > > <%once>;
> > > my $ET_CLASS =
$Bric::Biz::ElementType::VERSION
> > > ? 'Bric::Biz::ElementType'
> > > : 'Bric::Biz::AssetType';
> > > </%once>
> > > <%perl>;
> > > my $melem = $image->get_element;
> > >
> > > # Try to find an existing thumbnail image.
> > > if (my $thumb = $melem->get_related_media)
{
> > > return $thumb;
> > > }
> > >
> > > # We don't need the URI but calling it before
_thumb_file will
> > > ensure that a
> > > # thumbnail is created if it doesn't already
exist.
> > > $image->thumbnail_uri;
> > >
> > > # XXX Yeah yeah, I know I shouldn't call a
private method...
> > > my $path = $image->_thumb_file;
> > > my $image_fn = $image->get_file_name;
> > > my $thumb_fn =
"$file_prefix$image_fn$file_suffix";
> > > (my $uri =
URI::Escape::uri_unescape($image->get_uri))
> > > =~ s{Q$image_fnE$}{$thumb_fn};
> > >
> > > # Make sure that the thumbnail file exists.
> > > $burner->throw_error(
> > > qq{Thumbnail file "$path" does
not exist; is USE_THUMBNAILS
> > > enabled?}
> > > ) unless -f $path;
> > >
> > > # Look up the thumbnail element type.
> > > my $et = $ET_CLASS->lookup({ key_name
=> $key_name })
> > > or $burner->throw_error(qq{Could not
find the "$key_name" element
> > > type});
> > >
> > > # Create the thumbnail media document.
> > > my $thumb =
Bric::Biz::Asset::Business::Media->new({
> > > priority =>
$image->get_priority,
> > > title => $title_prefix .
$image->get_title . $title_suffix,
> > > description => $title_prefix .
$image->get_description .
> > > $title_suffix,
> > > site_id =>
$image->get_site_id,
> > > source__id =>
$image->get_source__id,
> > > media_type_id =>
$image->get_media_type->get_id,
> > > category__id =>
$image->get_category__id,
> > > element_type => $et,
> > > user__id =>
Bric::App::Session::get_user_id,
> > > });
> > >
> > > $thumb->set_cover_date($image-
> > >
>get_cover_date(Bric::Config::ISO_8601_FORMAT));
> > > $thumb->save;
> > >
> > > # Add the thumbnail image file to the media
document.
> > > open my $thumb_fh, '<', $path or die
"Cannot open '$path': $!n";
> > > $thumb->upload_file($thumb_fh =>
$thumb_fn);
> > > close $thumb_fh;
> > >
> > > # Check in the thumbnail document.
> > > $thumb->checkin;
> > > $thumb->save;
> > >
> > > # Add the thumbnail to the media document and
return it.
> > > $melem->set_related_media($thumb);
> > > $melem->save;
> > > return $thumb;
> > > </%perl>
> > >
> > > --
> > > Phillip Smith,
> > > Simplifier of Technology
> > > Community Bandwidth
> > > http://www.community
bandwidth.ca
> > >
> > >
> > >
> >
> > --
> > Phillip Smith,
> > Simplifier of Technology
> > Community Bandwidth
> > http://www.community
bandwidth.ca
> >
> >
> >
> >
--
Bret Dawson
Producer
Pectopah Productions Inc.
(416) 895-7635
bret pectopah.com
www.pectopah.com
|
|
| Re: Thumbnail.mc question |

|
2008-02-29 12:00:27 |
On Feb 29, 2008, at 06:38, Bret Dawson wrote:
> This time, with the template.
buildingbrics.com?
D
|
|
| Re: Thumbnail.mc question |

|
2008-02-29 18:57:06 |
I think I see what's happening here. I removed the
"Art" desk from the
Media workflow (not needed), and I can see that the newly
created
thumbnail asset:
* Has no events registered (like being created?)
* Is not on a desk (strange?)
I'm not having this problem on any sites that have an Art
desk. How
odd...?
Phillip.
On 29-Feb-08, at 6:38 AM, Bret Dawson wrote:
> This time, with the template.
>
> <%args>
> %element_names_and_sizes
> %needs_cropping
> $publish_images_on_story_preview
> $picture
> $target_image_element_type
> $media_workflow
> $publish_desk
> </%args>
> <%perl>
> use Bric::Util::Time qw(:all);
> use Date::Format;
> use DateTime;
>
> my $date = time;
> my $formatted_date = strfdate($date);
> # $m->out($formatted_date . '<br>');
> # $m->out('Today is: ' . DateTime->now(time_zone
=> 'Canada/
> Eastern')->strftime("%Y/%m/%d") .
'<br>');
>
> my ($picture_is_good, $format, $scolding, $user,
$new_media_document);
>
> if (!$story->get_user__id) {
> $user = Bric::App::Session->get_user_id;
> } else {
> $user = $story->get_user__id;
> }
>
> #pull out the media document inside the element and
make sure it's a
> picture
> if ($picture->get_related_media) {
> $scolding = $m->scomp('/util/image_check.mc',
> pic => $picture->get_related_media
> );
> if ($scolding) {
> $m->out('<strong>' . $scolding .
'</strong><br>');
> } else {
> $picture_is_good = 1;
> $format = $burner->notes('ext');
> $burner->notes( ext => '' );
> }
> }
>
> if ($picture_is_good) {
> my (%check_list, %safe_list);
>
> #check for containers
> foreach my $container_type(keys
%element_names_and_sizes) {
> foreach my
$existing_container($picture->get_elements) {
> if (($existing_container->get_key_name eq
$container_type) && (!
> $check_list{$container_type})) {
>
> #OK, we're working with this one
> $check_list{$container_type} = 1;
> $safe_list{$existing_container->get_id} = 1;
> }
> }
> }
>
> #kill any duplicate containers
> foreach my $container_type(keys
%element_names_and_sizes) {
> foreach my
$existing_container($picture->get_elements) {
> if (($existing_container->get_key_name eq
$container_type) && (!
> $safe_list{$existing_container->get_id})) {
>
> #OK, we're deleting this one
> my killswitch;
> $killswitch[0] = $existing_container;
> $picture->delete_elements( killswitch);
> $picture->save;
> }
> }
> }
>
> #create any missing containers
> foreach my $container_type(keys
%element_names_and_sizes) {
> if (!$check_list{$container_type}) {
> my $required_container_type =
Bric::Biz::ElementType-
> >lookup({ 'key_name' => $container_type });
>
$picture->add_container($required_container_type);
> $picture->save;
> }
> }
>
> #OK, we now have all the containers we need.
> #Loop through them. If they already have pictures,
leave them alone.
> #If they don't have pictures, create them and relate
them.
> foreach my
$working_container($picture->get_containers(keys
> %element_names_and_sizes)) {
> if ($working_container->get_related_media) {
> my $thumbScolding =
$m->scomp('/util/image_check.mc',
> pic =>
$working_container->get_related_media
> );
> if ($thumbScolding) {
> #container has bad media file
> $m->out('<strong>' . $thumbScolding .
'</strong><br>');
> } else {
> #container has good media file, so leave it
alone
> }
> } else {
> #container is empty, so create image and relate it
to container
> my $target_element_type = Bric::Biz::ElementType-
> >lookup({key_name =>
$target_image_element_type});
>
> my $media_document_title =
$picture->get_related_media-
> >get_title . '-' .
$working_container->get_key_name;
>
> my %target_initial_state = (
> 'user__id' => $user,
> 'active' => 1,
> 'priority' => $story->get_priority,
> 'title' =>
$picture->get_related_media->get_title . '-' .
> $working_container->get_key_name,
> 'description' => '',
> 'workflow_id' => $media_workflow->get_id,
> 'element_type' => $target_element_type,
> 'site_id' => $story->get_site_id,
> 'source__id' =>
$picture->get_related_media->get_source__id,
> 'cover_date' => $formatted_date,
> # 'media_type_id' =>
$picture->get_related_media-
> >get_media_type->get_id,
> 'category__id' =>
$picture->get_related_media->get_category__id
> );
> my $new_file_name =
$picture->get_related_media->get_file_name;
> my $extension =
"_$element_names_and_sizes{$working_container-
> >get_key_name}.$format";
> $new_file_name =~ s/....$/$extension/;
> my $new_uri =
$picture->get_related_media->get_primary_category-
> >get_uri . DateTime->now(time_zone =>
'Canada/Eastern')-
> >strftime("%Y/%m/%d/") . $new_file_name;
>
> #check if there is already an image with the same
URI in the
> Bricolage library.
> #If there is, open that media document. Otherwise
create a new
> one.
> # $m->out('Looking for an existing media
document with this
> uri:<br>' .
$picture->get_related_media->get_primary_category-
> >get_uri . time2str("%Y/%m/%d/", $date) .
$new_file_name . '<br>');
> my existing_media_document =
Bric::Biz::Asset::Business::Media-
> >list({
> 'uri' => $new_uri,
> 'active' => 1
> });
>
> if ($existing_media_document[0]) {
> # $m->out('<br>Found existing one. URI is
' .
> $existing_media_document[0]->get_primary_uri .
'<br>');
> $new_media_document =
$existing_media_document[0];
> # $new_media_document->checkout({ user__id
=> $user });
> } else {
> $new_media_document =
>
Bric::Biz::Asset::Business::Media::Image->new(%target_in
itial_state);
>
$new_media_document->set_workflow_id($media_workflow->
get_id);
> $new_media_document->save;
>
> $publish_desk->accept({ asset =>
$new_media_document });
> $publish_desk->save;
>
> $new_media_document->checkin;
> }
>
>
> #Here we go, making the new image
> my $temp_file = "/tmp/$new_file_name";
> my $new_image = new Image::Magick;
>
$new_image->Read($picture->get_related_media->get_p
ath);
>
> if ($needs_cropping{'height_aspect'}) {
> # $m->out('<br><br>Going to
crop!');
> my $target_height =
int(($needs_cropping{'height_aspect'} *
> $picture->get_related_media->get_value('width'))
/
> $needs_cropping{'width_aspect'});
> $new_image->Crop( geometry =>
$picture->get_related_media-
> >get_value('width')."x$target_height+0+0"
);
> # } else {
> # $m->out('<br><br>NOT going to
crop!');
> }
> $new_image-
>
>Thumbnail($element_names_and_sizes{$working_container-
> >get_key_name});
> $new_image->Set(colorspace=>'RGB');
> $new_image->Write($temp_file);
> undef $new_image;
>
> #now upload our new image
> my $file_handler;
> open ($file_handler, "<$temp_file");
>
> $new_media_document->upload_file($file_handler,
$new_file_name,
>
$picture->get_related_media->get_media_type->get_na
me);
> #no need to close filehandler because upload_file
does it
> automatically
>
> #delete the temp image here
> unlink ($temp_file);
>
> #save and check in if required
> $new_media_document->save;
>
> if ($new_media_document->get_checked_out) {
> #
$publish_desk->checkin($new_media_document);
> $new_media_document->checkin;
> }
>
> if ($publish_images_on_story_preview eq 'Yes') {
> # $m->out('Got the go-ahead to publish images
on
> preview<br><br>');
> unless
($new_media_document->get_publish_status) {
> # $m->out('Trying to publish "' .
$new_media_document-
> >get_title . '".<br>');
>
$burner->publish_another($new_media_document,$picture-
> >get_related_media->get_cover_date,1);
> }
> }
>
> #relate the image to the container
>
$working_container->set_related_media($new_media_document
);
> $working_container->save;
> }
> }
> }
> </%perl>
>
> On Fri, 2008-02-29 at 09:20 -0500, Bret Dawson wrote:
>> Hi Phillip.
>>
>> I've posted the current image_resize_and_relate.mc
here. It will
>> optionally publish thumbnails when they're created,
based on an
>> argument
>> you can set when you call the template. (This has
the effect of
>> publishing the images when the story calling them
into existence is
>> previewed.)
>>
>> The original reason for this was that we had
Bricolage publishing
>> to one
>> front-end Sportsnet machine, which was rsyncing
every minute with
>> several other machines. Sometimes the front page
would be published
>> and
>> rsynced onto on all the front-end machines before
the story itself
>> finished, and that would cause broken thumbnail
images on the home
>> page
>> for a minute.
>>
>> Doing it this way allowed us to be sure the images
would all be on
>> the
>> production machines before the home page got
there.
>>
>> Not sure if this helps, but there you go.
>>
>> Cheers,
>>
>> Bret
>>
>>
>> On Wed, 2008-02-27 at 00:57 -0500, Phillip Smith
wrote:
>>> Just a quick follow-up on this: Any thoughts on
how I could force
>>> the
>>> publish of the thumbnail image at the time of
its creation?
>>>
>>> Phillip.
>>>
>>> On 26-Feb-08, at 12:33 AM, Phillip Smith
wrote:
>>>
>>>>
>>>> I've been using the /util/thumbnail.mc for
ages now (and love it)
>>>> but, on one site, I've found that it
suddenly stopped publishing
>>>> the
>>>> thumbnails. They're created, but when I
publish the story, they
>>>> don't publish with it. They used to -- not
sure what's changed?
>>>> Nothing in the log to indicate an error.
Code in question is below.
>>>>
>>>> The odd thing is, it's there in the
preview. But, when I publish, I
>>>> get a broken image link on the published
story. I can find the
>>>> thumbnail and publish it, but that kinda
defeats the whole purpose.
>>>> Thoughts?
>>>>
>>>> <%args>
>>>> $image
>>>> $key_name =>
$image->get_element_key_name
>>>> $file_prefix => 'thumb-'
>>>> $file_suffix => ''
>>>> $title_prefix => 'Thumbnail for '
>>>> $title_suffix => ''
>>>> </%args>
>>>> <%once>;
>>>> my $ET_CLASS =
$Bric::Biz::ElementType::VERSION
>>>> ? 'Bric::Biz::ElementType'
>>>> : 'Bric::Biz::AssetType';
>>>> </%once>
>>>> <%perl>;
>>>> my $melem = $image->get_element;
>>>>
>>>> # Try to find an existing thumbnail image.
>>>> if (my $thumb =
$melem->get_related_media) {
>>>> return $thumb;
>>>> }
>>>>
>>>> # We don't need the URI but calling it
before _thumb_file will
>>>> ensure that a
>>>> # thumbnail is created if it doesn't
already exist.
>>>> $image->thumbnail_uri;
>>>>
>>>> # XXX Yeah yeah, I know I shouldn't call a
private method...
>>>> my $path = $image->_thumb_file;
>>>> my $image_fn = $image->get_file_name;
>>>> my $thumb_fn =
"$file_prefix$image_fn$file_suffix";
>>>> (my $uri =
URI::Escape::uri_unescape($image->get_uri))
>>>> =~ s{Q$image_fnE$}{$thumb_fn};
>>>>
>>>> # Make sure that the thumbnail file
exists.
>>>> $burner->throw_error(
>>>> qq{Thumbnail file "$path" does
not exist; is USE_THUMBNAILS
>>>> enabled?}
>>>> ) unless -f $path;
>>>>
>>>> # Look up the thumbnail element type.
>>>> my $et = $ET_CLASS->lookup({ key_name
=> $key_name })
>>>> or $burner->throw_error(qq{Could not
find the "$key_name" element
>>>> type});
>>>>
>>>> # Create the thumbnail media document.
>>>> my $thumb =
Bric::Biz::Asset::Business::Media->new({
>>>> priority =>
$image->get_priority,
>>>> title => $title_prefix .
$image->get_title .
>>>> $title_suffix,
>>>> description => $title_prefix .
$image->get_description .
>>>> $title_suffix,
>>>> site_id =>
$image->get_site_id,
>>>> source__id =>
$image->get_source__id,
>>>> media_type_id =>
$image->get_media_type->get_id,
>>>> category__id =>
$image->get_category__id,
>>>> element_type => $et,
>>>> user__id =>
Bric::App::Session::get_user_id,
>>>> });
>>>>
>>>> $thumb->set_cover_date($image-
>>>>>
get_cover_date(Bric::Config::ISO_8601_FORMAT));
>>>> $thumb->save;
>>>>
>>>> # Add the thumbnail image file to the media
document.
>>>> open my $thumb_fh, '<', $path or die
"Cannot open '$path': $!n";
>>>> $thumb->upload_file($thumb_fh =>
$thumb_fn);
>>>> close $thumb_fh;
>>>>
>>>> # Check in the thumbnail document.
>>>> $thumb->checkin;
>>>> $thumb->save;
>>>>
>>>> # Add the thumbnail to the media document
and return it.
>>>> $melem->set_related_media($thumb);
>>>> $melem->save;
>>>> return $thumb;
>>>> </%perl>
>>>>
>>>> --
>>>> Phillip Smith,
>>>> Simplifier of Technology
>>>> Community Bandwidth
>>>> http://www.community
bandwidth.ca
>>>>
>>>>
>>>>
>>>
>>> --
>>> Phillip Smith,
>>> Simplifier of Technology
>>> Community Bandwidth
>>> http://www.community
bandwidth.ca
>>>
>>>
>>>
>>>
> --
> Bret Dawson
> Producer
> Pectopah Productions Inc.
> (416) 895-7635
> bret pectopah.com
> www.pectopah.com
>
--
Phillip Smith,
Simplifier of Technology
Community Bandwidth
http://www.community
bandwidth.ca
|
|
| Re: Thumbnail.mc question |

|
2008-03-04 12:28:42 |
On Feb 29, 2008, at 16:57, Phillip Smith wrote:
> I think I see what's happening here. I removed the
"Art" desk from
> the Media workflow (not needed), and I can see that the
newly
> created thumbnail asset:
>
> * Has no events registered (like being created?)
The template needs to add those events.
> * Is not on a desk (strange?)
Yep, the template needs to put it on a valid desk.
Best,
David
|
|
| Re: Thumbnail.mc question |

|
2008-03-11 13:03:07 |
On 4-Mar-08, at 1:28 PM, David E. Wheeler wrote:
> On Feb 29, 2008, at 16:57, Phillip Smith wrote:
>
>> I think I see what's happening here. I removed the
"Art" desk from
>> the Media workflow (not needed), and I can see that
the newly
>> created thumbnail asset:
>>
>> * Has no events registered (like being created?)
>
> The template needs to add those events.
It needs to add the events specifically? I.e., they're not
added by
the act of checking-in, or saving the media via the
template? Just
want to double-confirm that.
Phillip.
--
Phillip Smith,
Simplifier of Technology
Community Bandwidth
http://www.community
bandwidth.ca
|
|
|
|