Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Bricolage: users

Access image properties

 

 

Bricolage users RSS feed   Index | Next | Previous | View Threaded


rs at plusw

Nov 10, 2010, 2:09 AM

Post #1 of 8 (760 views)
Permalink
Access image properties

How can I access properties of a related image (like width, height etc )?
Didn't find anything.

Rolf Schaufelberger


zdravko.balorda at siix

Nov 10, 2010, 2:26 AM

Post #2 of 8 (731 views)
Permalink
Re: Access image properties [In reply to]

Rolf Schaufelberger wrote:
> How can I access properties of a related image (like width, height etc )?
> Didn't find anything.
>
> Rolf Schaufelberger
>


% my $c = $st->get_container('related_media');
% my ($rm) = $c->get_related_media if ($c);
% if($rm) {
% my $img_sgn = ($rm->get_value('height') > $rm->get_value('width')) ? ... : ...;

just use auto-populated fields as usual.
Zdravko


rs at plusw

Nov 10, 2010, 1:36 PM

Post #3 of 8 (728 views)
Permalink
Re: Access image properties [In reply to]

Am 10.11.2010 um 11:26 schrieb Zdravko Balorda:

> Rolf Schaufelberger wrote:
>> How can I access properties of a related image (like width, height etc )?
>> Didn't find anything.
>> Rolf Schaufelberger
>
>
> % my $c = $st->get_container('related_media');
> % my ($rm) = $c->get_related_media if ($c);
> % if($rm) {
> % my $img_sgn = ($rm->get_value('height') > $rm->get_value('width')) ? ... : ...;
>
> just use auto-populated fields as usual.
> Zdravko

Ok, works.

To help me to understand Bricolage internals better:

Doesn't get_related_media return a Bric::Biz:Asset::Business::Media::* object ?
The get_value method belongs to Bric::Element::Container or not ?

Rolf


bret at pectopah

Nov 10, 2010, 2:17 PM

Post #4 of 8 (725 views)
Permalink
Re: Access image properties [In reply to]

Hi Rolf


> To help me to understand Bricolage internals better:
>
> Doesn't get_related_media return a Bric::Biz:Asset::Business::Media::* object ?
> The get_value method belongs to Bric::Element::Container or not ?
>

It's true. But Bric::Biz::Asset::Business has a get_value() method,
which is a convenience shortcut to $asset->get_element->get_value().
Bric::Biz:Asset::Business::Media::Image just inherits it.


Hope this helps,

Bret


--
Bret Dawson
Producer
Pectopah Productions Inc.
(416) 895-7635
bret [at] pectopah
www.pectopah.com


rs at plusw

Nov 10, 2010, 2:31 PM

Post #5 of 8 (736 views)
Permalink
Re: Access image properties [In reply to]

Am 10.11.2010 um 23:17 schrieb Bret Dawson:

> Hi Rolf
>
>
>> To help me to understand Bricolage internals better:
>>
>> Doesn't get_related_media return a Bric::Biz:Asset::Business::Media::* object ?
>> The get_value method belongs to Bric::Element::Container or not ?
>>
>
> It's true. But Bric::Biz::Asset::Business has a get_value() method,
> which is a convenience shortcut to $asset->get_element->get_value().
> Bric::Biz:Asset::Business::Media::Image just inherits it.
>
>
> Hope this helps,

Ok, found in the docs, I must have been blind :-) .
Thanks.

Rolf Schaufelberger


zdravko.balorda at siix

Nov 10, 2010, 10:33 PM

Post #6 of 8 (720 views)
Permalink
Re: Access image properties [In reply to]

Rolf Schaufelberger wrote:
> Am 10.11.2010 um 11:26 schrieb Zdravko Balorda:
>
>> Rolf Schaufelberger wrote:
>>> How can I access properties of a related image (like width, height etc )?
>>> Didn't find anything.
>>> Rolf Schaufelberger
>>
>> % my $c = $st->get_container('related_media');
>> % my ($rm) = $c->get_related_media if ($c);
>> % if($rm) {
>> % my $img_sgn = ($rm->get_value('height') > $rm->get_value('width')) ? ... : ...;
>>
>> just use auto-populated fields as usual.
>> Zdravko
>
> Ok, works.
>
> To help me to understand Bricolage internals better:
>
> Doesn't get_related_media return a Bric::Biz:Asset::Business::Media::* object ?

From documentation:
$media = $container->get_related_media;
If a media document is related to this container element, this method returns
that media object.
But correct me if I'am wrong, because I found some of my code saying:
% my @img = $c->get_related_media if ($c);
% my $r_img = shift @img;




> The get_value method belongs to Bric::Element::Container or not ?
>

Yes, but width is an element of media not the container related_media. I think. :)


david at kineticode

Nov 11, 2010, 8:17 AM

Post #7 of 8 (730 views)
Permalink
Re: Access image properties [In reply to]

On Nov 10, 2010, at 10:33 PM, Zdravko Balorda wrote:

> From documentation:
> $media = $container->get_related_media;
> If a media document is related to this container element, this method returns
> that media object.
> But correct me if I'am wrong, because I found some of my code saying:
> % my @img = $c->get_related_media if ($c);
> % my $r_img = shift @img;

You just need

my $r_img = $c ? $c->get_related_media : undef;

Never put "if bool" at the end of a `my ` statement. You'll end up with junk in your variable if $c is undef.

> Yes, but width is an element of media not the container related_media. I think. :)

Correct.

David


zdravko.balorda at siix

Nov 12, 2010, 3:06 AM

Post #8 of 8 (717 views)
Permalink
Re: Access image properties [In reply to]

>> % my @img = $c->get_related_media if ($c);
>> % my $r_img = shift @img;
>
> You just need
>
> my $r_img = $c ? $c->get_related_media : undef;
>
> Never put "if bool" at the end of a `my ` statement. You'll end up with junk in your variable if $c is undef.

Thank you for this suggestion. I'm fed up with that spaghetti code that
didn't know how to fix. :)

Zdravko

Bricolage users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.