Anyone know if there is a way to change it from white?
Something like: $image->bgcolour('hexvalue'); Maybe?
Mo
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Anyone know if there is a way to change it from white?
Something like: $image->bgcolour('hexvalue'); Maybe?
Mo
Hm. I was under the impression that SetWidth never creates a background?
Maybe you are referring to "PaddedImage" and the like? I had to change the color once and subclassed Image for that purpose.
Something like:
class BetterImage extends Image
{
public function generatePaddedImage(GD $gd, $width, $height) {
return $gd->paddedResize($width, $height, 'cccccc');
}
public function SetWidth($width) {
if($width == $this->getWidth())
return $this;
return $this->getFormattedImage('SetWidth', $width);
}
public function SetHeight($height) {
if($height == $this->getHeight())
return $this;
return $this->getFormattedImage('SetHeight', $height);
}
}
Then instead of using "Image", use "BetterImage" in your $has_one relations.
The above class also doesn't resize Images when they already have the correct dimensions which will improve quality...
Sorry, I should have been more specific, I am using:
$Image.setWidth(80,80);
In the template language. It pads out the image if it has to, with a background colour.
I think I Ideally might have to use a similar method to scale and crop all images square, but the setWidth method would do for this stage of development.
Mo
I'm not aware of a way to alter the background color without subclassing or decorating. Simply create a subclass as proposed above and override the generate functions you need to customize.
Hmm, I just found out I could do:
<% control croppedImage(80,80) %>
<img src="$URL" />
<% end_control %>
Which is pretty much exactly what I wanted initially. I think you might be right about the subclassing. I will have to look into it :).
Cheers,
Mo