Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS /

Size of ImageField thumbnail in Backend


Reply


7 Posts   767 Views

Avatar
Pipifix

Community Member, 54 Posts

16 March 2012 at 5:46am

Hi everybody.

The goal:
My client want a bigger thumbnail of the image attached to a dataobject.

What I've done so far:
The dataobjectitems are houses with a bunch of values. The image is bind with static $has_one = array('Image' => 'Image'   );
The imagefield is generated in getCMSFields with $fields->addFieldToTab("Root.Main", new ImageField('Image', 'Bild des Objektes', Null, Null, Null, 'images-immodatabase'));

My question is:
How to alter the size of the allready attached image. Is there a simple config line? Or do i have to edit the core (Imagefield)?
Thanks for your help.

Pipifix.

Avatar
Pipifix

Community Member, 54 Posts

20 March 2012 at 6:06am

bump

Avatar
novaweb

Community Member, 115 Posts

20 March 2012 at 11:08am

Edited: 20/03/2012 11:08am

Pipifix,

Not sure if this answers your question, but in your template you can call Graphic Draw functions via SilverStripe.

In your template:

$Image.SetWidth(250)

See: http://api.silverstripe.org/2.4/sapphire/filesystem/Image.html for a list of available methods on Image objects.

Cheers,
Josh

Avatar
novaweb

Community Member, 115 Posts

20 March 2012 at 11:10am

Let me know if you were wanting to increase the image size in the back end (CMS), and not on the front end (template) of your site.

Avatar
Pipifix

Community Member, 54 Posts

30 March 2012 at 8:39am

Thanks novaweb.

I meant the thumbnail preview in the ModelAdmin (=Backend).

Pipifix

Avatar
Pipifix

Community Member, 54 Posts

10 April 2012 at 10:24pm

Nobody?

Avatar
zenmonkey

Community Member, 528 Posts

12 April 2012 at 2:55am

Edited: 12/04/2012 2:55am

I've done custom thumbnails in modeladmin table.

//first add you're custom thumbnail field to the Summary Field
static $summary_fields = array('Thumb');

//then create a a custom getter for it
public function getThumb(){
$image = DataObject::get_by_id("File", $this->ImageID);
if ($image){
return $image->setWidth(50);
} else {
return "No Image Available";
}
}


I'm assuming that your image is held under ImageID, and for the return function you can use any of the standard image functions.

Now this won't change the size of the thumbnail in the CMS ImageField, unfortunately the current ImageFIeld doesn't allow you to customize the thumbnail size

I think I also saw a tutorial for this on SSBits.com, not sure if their implementation is better. I had a solution when by the time I saw it there

Cheers