-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image component - original width and height #5
Conversation
Moin @lpheller , Wäre cool wenn du nochmal deine Meinung dazu hier kommentierst und mich markierst! Thanks! |
Eine Lösung rein über CSS geht mit Lazysizes und dem dem gewünschten Verhalten Dazu wären wohl die Optionen vermutlich:
Warum Dropzone Verzögerung?sending(file, xhr, formData) {
formData.append("fileWidth", file.width);
// request gets send immediately when a file is added
// but file.width is undefined until dropzone fires its "thumbnail" event
}, Davon ausgehend, dass wir die Bilddimensionen irgendwie zugänglich machen würde ich diesen PR erstmal offen lassen und zu einem späteren Zeitpunkt mit den Änderungen aktualisieren. |
Ich würde vorschlagen, das man die width in den custom properties speichern kann. In der Image componente würde ich dann prüfen ob die custom_property public function __construct(Media $image, $width = null, ...)
{
// ...
if(is_null($width)) {
$width = $image->custom_properties['width'] ?? 0;
}
$this->width = $width;
// ...
} Wie genau das speichern der width beim upload funktioniert kann ich mir mal angucken. |
Wie es beim Upload gespeichert werden kann hatte ich für mich schon mal durchgespielt. @cbl // Ignite\Crud\Repositories\MediaRepository
protected function storeMediaToModel($request, $model)
{
// ...
$dimensions = [
'width' => ImageFactory::load($request->media->path())->getWidth(),
'height' => ImageFactory::load($request->media->path())->getHeight(),
];
$customProperties = array_merge($customProperties, $dimensions);
$media = $model->addMedia($request->media)
->preservingOriginal()
->withCustomProperties($customProperties)
->toMediaCollection($request->collection);
// ...
} |
This PR adds the opportunity to use the original image width or height. This is e.g. required if an image shouldn't use all of the available space.
It checks whether the html width (or height) attribute is set to "original" and retrieves the corresponding original dimension using the intervention image library. Passing a fixed size is still possible.
@jannescb I changed the blade view of the image component to use the attribute bag. That way not every single attribute needs a wrapping if statement and it seems more open to further additions. I hope you agree with that?