Image Editor Height/Width

I want to create an image which is a specific size. I defined height (400) and width (270) constants that I am using and I have built the FileUpload component like the following. However, after using the image editor, it crops the image incorrectly. It creates an image a few pixels smaller than required! How can I create an image with the exact sizes I want.
FileUpload::make('poster')
->panelAspectRatio($this->aspectRatio())
->imageCropAspectRatio($this->aspectRatio())
->imagePreviewHeight((string) Movie::POSTER_HEIGHT)
->imageResizeTargetHeight((string) Movie::POSTER_HEIGHT)
->imageResizeTargetWidth((string) Movie::POSTER_WIDTH)
->image()
->imageEditor()
->imageEditorAspectRatios([
$this->aspectRatio(),
]);

protected function aspectRatio(): string
{
return Movie::POSTER_WIDTH . ':' . Movie::POSTER_HEIGHT;
}
FileUpload::make('poster')
->panelAspectRatio($this->aspectRatio())
->imageCropAspectRatio($this->aspectRatio())
->imagePreviewHeight((string) Movie::POSTER_HEIGHT)
->imageResizeTargetHeight((string) Movie::POSTER_HEIGHT)
->imageResizeTargetWidth((string) Movie::POSTER_WIDTH)
->image()
->imageEditor()
->imageEditorAspectRatios([
$this->aspectRatio(),
]);

protected function aspectRatio(): string
{
return Movie::POSTER_WIDTH . ':' . Movie::POSTER_HEIGHT;
}
3 Replies
trovster
trovster3mo ago
My movie poster dimensions should be 270x400, but it generates an image that is 270x399. My movie still dimensions should be 470x190 but it generates an image that is 468x189…! Does anyone have any suggestions for this strange issue with the cropping of images?
CGM
CGM2mo ago
I think if you get rid of
->imageEditorAspectRatios([
$this->aspectRatio(),
])
->imageEditorAspectRatios([
$this->aspectRatio(),
])
you're good to go. ->imageCropAspectRatio($this->aspectRatio()) is enough I think.
trovster
trovster2w ago
No, this does nothing. Getting rid of this still crops incorrectly. I have just tried and I get an image which is 269x399 for a poster, which is wrong. Also, if I don't open the editor, it doesn't resize at all! I have just been testing this again and it seems like the following has worked, if I also add ->imageResizeMode('force').
protected function aspectRatio(): string
{
return strval(Movie::POSTER_HEIGHT / Movie::POSTER_WIDTH);
}
protected function aspectRatio(): string
{
return strval(Movie::POSTER_HEIGHT / Movie::POSTER_WIDTH);
}
Want results from more Discord servers?
Add your server