Skip to content

Preview API: different aspect ratio / scale options #31268

Closed as not planned
Closed as not planned

Description

@felix-schwarz

Talking with @DeepDiver1975 about the Preview API, the topic of aspect ratio scaling came up. Right now, it appears the y parameter is ignored if the aspect ratio parameter a is set.

This works for wide images, but would return a larger-than-requested image for portrait images.

Landscape Example:

  • image size: 200 x 100
  • maximum size: 20 x 20
  • returned image size: 20 x 10

Portrait Example:

  • image size: 100 x 200
  • maximum size: 20 x 20
  • returned image size: 20 x 40

Ideally, Preview API would allow clients to pick one of these scaling methods:

  • ignore: ignore aspect ratio

  • aspect fit: scale image to fit the requested size while maintaining the aspect ratio. The resulting image can be smaller than the requested size.

  • aspect fill: scale image to fill the requested size while maintaining the aspect ratio, cutting off parts of the image if needed. The resulting image is exactly the requested size.

Activity

  1. changed the title [-]Preview API: different aspect ratio scale options[/-] [+]Preview API: different aspect ratio / scale options[/+] on Apr 25, 2018
  2. ownclouders commented on Apr 25, 2018

    @ownclouders
    Contributor

    GitMate.io thinks possibly related issues are #13516 (Previews with aspect ratio need to be properly cached), #16551 (Thumbnail API asks for a preview twice each time), #19548 (Add option to configure preview (and thumbnail, ect.) location), #19958 (Streaming API?), and #6550 ("Enable Previews" config option should default to "false").

  3. michaelstingl commented on May 8, 2018

    @michaelstingl

    There have been some limitations in the past:

    Maybe this can be done right with the new implementation…

  4. ownclouders commented on Jun 16, 2018

    @ownclouders
    Contributor

    Hey, this issue has been closed because the label status/STALE is set and there were no updates for 7 days. Feel free to reopen this issue if you deem it appropriate.

    (This is an automated comment from GitMate.io.)

  5. added this to the backlog milestone on Jan 16, 2019
  6. stale commented on Sep 20, 2021

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.

  7. DeepDiver1975 commented on Jun 19, 2026

    @DeepDiver1975
    Contributor

    🤖 Automated issue analysis by Claude Code review agent.

    This 2018 enhancement requested that the Preview API offer selectable aspect-ratio / scale modes (ignore, aspect fit, aspect fill). This capability has since been implemented in current owncloud/core and is exposed through the WebDAV preview API query parameters.

    Where it is implemented

    The preview engine now supports the requested scaling modes via the mode and a parameters:

    • lib/private/Preview.php defines the scale modes and the keep-aspect flag:

      public const MODE_FILL = 'fill';
      public const MODE_COVER = 'cover';
      private $keepAspect = false;
      private $mode = self::MODE_FILL;
      // ...
      public function setMode($mode) { ... }     // "Set whether to cover or fill the specified dimensions"
      public function setKeepAspect($keepAspect) { ... }
    • lib/private/Files/Node/File.php (getThumbnail(), @since 10.1.0) maps the preview API request parameters onto these options:

      $keepAspect = \array_key_exists('a', $options) ? true : false;
      $mode = \array_key_exists('mode', $options) ? $options['mode'] : 'fill';
      // ...
      $preview->setMode($mode);
      $preview->setKeepAspect($keepAspect);
    • apps/dav/lib/Files/PreviewPlugin.php forwards the request query parameters into getThumbnail($queryParams), so these are client-controllable via the preview endpoint.

    Mapping to the three modes requested in this issue

    • ignore (ignore aspect ratio): omit the a parameter → keepAspect = false.
    • aspect fit (fit within the box, may be smaller than requested): a set with mode=fill (the default) → MODE_FILL.
    • aspect fill (fill the box exactly, cropping overflow): a set with mode=cover → MODE_COVER.

    Behaviour is covered by acceptance tests tests/acceptance/features/apiWebdavPreviews/previewsExactSizing.feature and previewsAutoAdustedSizing.feature.

    Since the requested scaling options are now available, this issue appears resolved and is being closed. If a specific behaviour is still missing, please reopen with details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions