Mailing List Archive

find_or_create_alternate just returns the original image
Hi everybody,

I'm just starting to use the find_or_create_alternate() method to make
thumbnails, and I must be doing something wrong. When I try something
like this:

my $size = 240;
my $thumb = $pic->find_or_create_alternate({
title_prefix => '',
title_suffix => '-' . $size,
file_suffix => '_sized_nicely,
et_key_name => 'auto_generated_image',
relate => 0,
transformer => sub {
shift->scale( xpixels => $element_names_and_sizes{$size} );
},
});

...no new media document is created, and the $thumb returned is the
original $pic. Any idea what I'm doing incorrectly?


Thanks,

Bret



--
Bret Dawson
Producer
Pectopah Productions Inc.
(416) 895-7635
bret@pectopah.com
www.pectopah.com
Re: find_or_create_alternate just returns the original image [ In reply to ]
On Apr 8, 2011, at 3:10 PM, Bret Dawson wrote:

> Hi everybody,
>
> I'm just starting to use the find_or_create_alternate() method to make
> thumbnails, and I must be doing something wrong. When I try something
> like this:
>
> my $size = 240;
> my $thumb = $pic->find_or_create_alternate({
> title_prefix => '',
> title_suffix => '-' . $size,
> file_suffix => '_sized_nicely,
> et_key_name => 'auto_generated_image',
> relate => 0,
> transformer => sub {
> shift->scale( xpixels => $element_names_and_sizes{$size} );
> },
> });
>
> ...no new media document is created, and the $thumb returned is the
> original $pic. Any idea what I'm doing incorrectly?

Is $pic a auto_generated_image already?

Best,

David
Re: find_or_create_alternate just returns the original image [ In reply to ]
On Apr 8, 2011, at 3:10 PM, Bret Dawson wrote:

> Hi everybody,
>
> I'm just starting to use the find_or_create_alternate() method to make
> thumbnails, and I must be doing something wrong. When I try something
> like this:
>
> my $size = 240;
> my $thumb = $pic->find_or_create_alternate({
> title_prefix => '',
> title_suffix => '-' . $size,
> file_suffix => '_sized_nicely,
> et_key_name => 'auto_generated_image',
> relate => 0,
> transformer => sub {
> shift->scale( xpixels => $element_names_and_sizes{$size} );
> },
> });
>
> ...no new media document is created, and the $thumb returned is the
> original $pic. Any idea what I'm doing incorrectly?

Is $pic a auto_generated_image already?

Best,

David
Re: find_or_create_alternate just returns the original image [ In reply to ]
Hi David,

> Is $pic a auto_generated_image already?

No, it's just an "image". Do they need to be the same type?


Thanks,

Bret



On Sat, 2011-04-09 at 09:06 -0700, David E. Wheeler wrote:
> On Apr 8, 2011, at 3:10 PM, Bret Dawson wrote:
>
> > Hi everybody,
> >
> > I'm just starting to use the find_or_create_alternate() method to make
> > thumbnails, and I must be doing something wrong. When I try something
> > like this:
> >
> > my $size = 240;
> > my $thumb = $pic->find_or_create_alternate({
> > title_prefix => '',
> > title_suffix => '-' . $size,
> > file_suffix => '_sized_nicely,
> > et_key_name => 'auto_generated_image',
> > relate => 0,
> > transformer => sub {
> > shift->scale( xpixels => $element_names_and_sizes{$size} );
> > },
> > });
> >
> > ...no new media document is created, and the $thumb returned is the
> > original $pic. Any idea what I'm doing incorrectly?
>

>
> Best,
>
> David
>
>

--
Bret Dawson
Producer
Pectopah Productions Inc.
(416) 895-7635
bret@pectopah.com
www.pectopah.com
Re: find_or_create_alternate just returns the original image [ In reply to ]
Hi David,

> Is $pic a auto_generated_image already?

No, it's just an "image". Do they need to be the same type?


Thanks,

Bret



On Sat, 2011-04-09 at 09:06 -0700, David E. Wheeler wrote:
> On Apr 8, 2011, at 3:10 PM, Bret Dawson wrote:
>
> > Hi everybody,
> >
> > I'm just starting to use the find_or_create_alternate() method to make
> > thumbnails, and I must be doing something wrong. When I try something
> > like this:
> >
> > my $size = 240;
> > my $thumb = $pic->find_or_create_alternate({
> > title_prefix => '',
> > title_suffix => '-' . $size,
> > file_suffix => '_sized_nicely,
> > et_key_name => 'auto_generated_image',
> > relate => 0,
> > transformer => sub {
> > shift->scale( xpixels => $element_names_and_sizes{$size} );
> > },
> > });
> >
> > ...no new media document is created, and the $thumb returned is the
> > original $pic. Any idea what I'm doing incorrectly?
>

>
> Best,
>
> David
>
>

--
Bret Dawson
Producer
Pectopah Productions Inc.
(416) 895-7635
bret@pectopah.com
www.pectopah.com
Re: find_or_create_alternate just returns the original image [ In reply to ]
On Apr 9, 2011, at 10:18 AM, Bret Dawson wrote:

> No, it's just an "image". Do they need to be the same type?

No, they should not be. I'm not sure, you'll have to debug it, I'm afraid. Finding an existing auto_generated_image is the only path to an early return I can see in the method. You're getting back exactly the same object?

Oh, wait, is it a Bric::Biz::Asset::Business::Media::Image? Only an Image object implements the needed functionality.

Best,

David
Re: find_or_create_alternate just returns the original image [ In reply to ]
On Apr 9, 2011, at 10:18 AM, Bret Dawson wrote:

> No, it's just an "image". Do they need to be the same type?

No, they should not be. I'm not sure, you'll have to debug it, I'm afraid. Finding an existing auto_generated_image is the only path to an early return I can see in the method. You're getting back exactly the same object?

Oh, wait, is it a Bric::Biz::Asset::Business::Media::Image? Only an Image object implements the needed functionality.

Best,

David
Re: find_or_create_alternate just returns the original image [ In reply to ]
> No, they should not be. I'm not sure, you'll have to debug it, I'm afraid. Finding an existing auto_generated_image is the only path to an early return I can see in the method. You're getting back exactly the same object?
>
> Oh, wait, is it a Bric::Biz::Asset::Business::Media::Image? Only an Image object implements the needed functionality.
>

Yeah, it is. Both "image" and "auto_generated_image" are image objects.
But yes, the object returned is the exact same one I'm calling
find_or_create_alternate() on.

I'll do some debugging and report back. Prepare to learn about a typo in
my template!

Thanks,

Bret


> Best,
>
> David

--
Bret Dawson
Producer
Pectopah Productions Inc.
(416) 895-7635
bret@pectopah.com
www.pectopah.com
Re: find_or_create_alternate just returns the original image [ In reply to ]
Hi,

I just started using this function two days ago and it works fine.
May be something wrong with $element_names_and_sizes{$size} ?

Am 09.04.2011 um 19:18 schrieb Bret Dawson:

> Hi David,
>
>> Is $pic a auto_generated_image already?
>
> No, it's just an "image". Do they need to be the same type?
>
>
> Thanks,
>
> Bret
>
>
>
> On Sat, 2011-04-09 at 09:06 -0700, David E. Wheeler wrote:
>> On Apr 8, 2011, at 3:10 PM, Bret Dawson wrote:
>>
>>> Hi everybody,
>>>
>>> I'm just starting to use the find_or_create_alternate() method to make
>>> thumbnails, and I must be doing something wrong. When I try something
>>> like this:
>>>
>>> my $size = 240;
>>> my $thumb = $pic->find_or_create_alternate({
>>> title_prefix => '',
>>> title_suffix => '-' . $size,
>>> file_suffix => '_sized_nicely,
>>> et_key_name => 'auto_generated_image',
>>> relate => 0,
>>> transformer => sub {
>>> shift->scale( xpixels => $element_names_and_sizes{$size} );
>>> },
>>> });
>>>
>>> ...no new media document is created, and the $thumb returned is the
>>> original $pic. Any idea what I'm doing incorrectly?
>>
>
>>
>> Best,
>>
>> David
>>
>>
>
> --
> Bret Dawson
> Producer
> Pectopah Productions Inc.
> (416) 895-7635
> bret@pectopah.com
> www.pectopah.com
>

Mit freundlichen Grüßen
Rolf Schaufelberger
Geschäftsführer

plusW GmbH
Vorstadtstr. 61 -67 Tel. 07181 47 47 305
73614 Schorndorf Fax. 07181 47 45 344

www.plusw.de
www.mypixler.com
www.calendrino.de
Re: find_or_create_alternate just returns the original image [ In reply to ]
Hi everybody,

I just figured this out. The inital media document had a mixed-case
filename, but a lowercase URI format.

So the regex that was trying to change the initial image's URI into the
thumbnail's URI was failing to find the filename, which left the
"target" URI the same as the starter one. Then the lookup found the
image with the desired URI and returned the inital picture.

I've committed a patch and sent a pull request.


Cheers,

Bret


On Sun, 2011-04-10 at 19:51 +0200, Rolf Schaufelberger wrote:
> Hi,
>
> I just started using this function two days ago and it works fine.
> May be something wrong with $element_names_and_sizes{$size} ?
>
> Am 09.04.2011 um 19:18 schrieb Bret Dawson:
>
> > Hi David,
> >
> >> Is $pic a auto_generated_image already?
> >
> > No, it's just an "image". Do they need to be the same type?
> >
> >
> > Thanks,
> >
> > Bret
> >
> >
> >
> > On Sat, 2011-04-09 at 09:06 -0700, David E. Wheeler wrote:
> >> On Apr 8, 2011, at 3:10 PM, Bret Dawson wrote:
> >>
> >>> Hi everybody,
> >>>
> >>> I'm just starting to use the find_or_create_alternate() method to make
> >>> thumbnails, and I must be doing something wrong. When I try something
> >>> like this:
> >>>
> >>> my $size = 240;
> >>> my $thumb = $pic->find_or_create_alternate({
> >>> title_prefix => '',
> >>> title_suffix => '-' . $size,
> >>> file_suffix => '_sized_nicely,
> >>> et_key_name => 'auto_generated_image',
> >>> relate => 0,
> >>> transformer => sub {
> >>> shift->scale( xpixels => $element_names_and_sizes{$size} );
> >>> },
> >>> });
> >>>
> >>> ...no new media document is created, and the $thumb returned is the
> >>> original $pic. Any idea what I'm doing incorrectly?
> >>
> >
> >>
> >> Best,
> >>
> >> David
> >>
> >>
> >
> > --
> > Bret Dawson
> > Producer
> > Pectopah Productions Inc.
> > (416) 895-7635
> > bret@pectopah.com
> > www.pectopah.com
> >
>
> Mit freundlichen Grüßen
> Rolf Schaufelberger
> Geschäftsführer
>
> plusW GmbH
> Vorstadtstr. 61 -67 Tel. 07181 47 47 305
> 73614 Schorndorf Fax. 07181 47 45 344
>
> www.plusw.de
> www.mypixler.com
> www.calendrino.de
>
>
>
>
>
>
>

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