响应式全屏图像而不损失质量,可能吗?

发布于 2024-12-01 15:41:55 字数 397 浏览 0 评论 0原文

你好 stackoverflow 社区,希望你今天过得愉快 :)

开门见山: 我已经开始计划我的新作品集(顺便说一句,我是一名艺术总监)。我最初的想法不仅是让作品集响应式(我认为 1024x768px 一直到 2560x1600px),而且还通过全浏览器屏幕图像提供一些不错的作品预览。

正如你所料,我遇到了一个问题。设计为完全适合 2560x1600 像素的图像不会在不损失质量或扭曲的情况下调整为 1440x900 像素。

所以我真的可以利用你们的帮助和经验...是否有一个“完美”的图像尺寸可以完美地调整到以下分辨率:1024x768px、1280x800px、1280x1024px、1440x900px、1920x1080px、2560x1600px。有可能这样做吗?

我真的很感谢你的帮助。提前致谢 :)

Hallo community of stackoverflow, I hope you're having a nice day :)

Straight to the point :
I've started to plan on a new portfolio of mine (I am an art director bytheway). And my original idea was not to only make a portfolio responsive (I am thinking 1024x768px all the way up to 2560x1600px), but also have some nice work preview via full-browser-screen images.

And as you might expect I've encautered a problem. Image designed to fully fit 2560x1600px won't resize to lets say 1440x900px without loosing quality or being distorted.

So I could really use your help and experience guys... Is there a "perfect" image size that would resize beautifully to the following resolutions : 1024x768px, 1280x800px, 1280x1024px, 1440x900px, 1920x1080px, 2560x1600px. Is it even possible to do that ?

I really appreciate your help. Thanks in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

毁梦 2024-12-08 15:41:55

不要尝试将整个图像缩放到所有这些不同的分辨率,而是考虑保留纵横比(宽度:高度),同时缩放到接近(但大于)所需的分辨率,然后裁剪图像。

缩放图像和更改纵横比总是会导致失真。

Rather than trying to scale the entire image to all those different resolutions, consider preserving the aspect ratio (width : height) while scaling as close to (but larger than) the required resolution, and then cropping the image.

Scaling an image and changing the aspect ratio always causes distortion.

青朷 2024-12-08 15:41:55

不,不存在可以完美缩放到所有这些不同尺寸的图像,因为它们代表几种不同的形状或纵横比。将图像的宽度和高度缩放不同的量会导致图像扭曲,并且通常看起来不太好。

选项如下:

  1. 尽可能缩放图像(按比例),使其填充屏幕的一个维度,但不会完全填充另一个维度。这是可以显示的最大的未裁剪图像。
  2. (按比例)缩放图像,直到它完全填满屏幕。如果屏幕与图像的形状不完全相同,则需要过度缩放图像才能填充屏幕。显示图像将沿一个方向裁剪图像的一部分。这是缩放图像以完全“填满”屏幕的正常方式。如果创建的图像在边缘周围有一些“额外”且不重要的空间,那么由于填充尺寸过大而裁剪掉其中一些空间不会导致任何问题。
  3. 按照选项 #1 缩放图像,并使用协调的背景颜色填充屏幕上未被图像覆盖的任何区域。
  4. 创建与图像形状完全相同的容器或框架,然后缩放图像以填充该容器或框架。
  5. 非按比例缩放图像以完全填满整个屏幕。这将在一个方向上比另一个方向拉伸图像更多,并且图像会有些扭曲,但不会裁剪任何内容,并且会覆盖整个屏幕。圆形的东西会变成椭圆形,其他形状的东西会变形。

在所有情况下,您都希望分析可能的显示尺寸并选择形状与尽可能多的目标屏幕尺寸最接近的源图像。

No, there is no such thing as an image that will scale perfectly to all those different sizes because they represent several different shapes or aspect ratios. Scaling an image a different amount in width vs. height results in the image being distorted and generally does not look good.

The options are as follows:

  1. Scale the image (proportionally) as much as it can be scaled so that it fills one dimension of the screen and doesn't quite fill the other dimension. This is the largest uncropped image that can be displayed.
  2. Scale the image (proportionally) until it just completely fills the screen. If the screen is not exactly the same shape as the image, then the image will need to be overscaled in order to fill the screen. Displaying the image will crop part of the image along one direction. This is the normal way that an image is scaled to completely "fill" the screen. If the image is created with some "extra" and unimportant space around the edges than cropping some of that off because of the oversize scaling to fill will not result in any problem.
  3. Scale the image as in option #1 and use a coordinated background color to fill any area of the screen not covered by the image.
  4. Create a container or frame that is exactly the same shape as your image and scale the image to fill that.
  5. Scale the image non-proportionally to exactly fill the whole screen. This will stretch the image in one direction more than the other and the image will be distorted some, but nothing will be cropped and the entire screen will be covered. Round things will be elliptical and other shapes will be distorted.

In all cases, you want to analyze the likely display sizes and pick a source image that is closest in shape to as many target screen sizes as possible.

2024-12-08 15:41:55

您可以使用 Photoshop 或任何其他软件准备许多图像,然后使用响应式设计,您将能够为不同的屏幕尺寸显示足够的图像。

这是一个仅使用 css/html 的简单技巧:

成分

  • 具有所需比例的透明 PNG 图像
    (transparent-ratio-conserver.png)

  • 标签

  • 不同视口的不同图像(retina.jpg、desktop.jpg、
    table.jpg...)

这个想法是打开一个标签并为其分配一个透明图像(具有我们所需的比例)。我们还添加了 HTML 中的 class="responsive-image"。

<img src="img/transparent-ratio-conserver.png" class="responsive-image">

在 CSS 中,我们设置背景大小以适合,并选择图像的宽度。

.responsive-image{
    width: 100%;
    background-size: 100% 100%;
} 

最后,我们为每个视口提供正确的图像:

/* Retina display */
@media screen and (min-width: 1024px){
    .responsive-image{
        background-image: url('../img/retina.jpg');
    }
}
/* Desktop */
@media screen and (min-width: 980px) and (max-width: 1024px){
    .responsive-image{
        background-image: url('../img/desktop.jpg');
    }
}
/* Tablet */
@media screen and (min-width: 760px) and (max-width: 980px){
    .responsive-image{
        background-image: url('../img/tablet.jpg');
    }
}
/* Mobile HD */
@media screen and (min-width: 350px) and (max-width: 760px){
    .responsive-image{
        background-image: url('../img/mobile-hd.jpg');
    }
}
/* Mobile LD */
@media screen and (max-width: 350px){
    .responsive-image{
        background-image: url('../img/mobile-ld.jpg');
    }
} 

您可以从 此处下载演示

You can prepare many images using photoshop or any other software, then using responsive design you would be able to display the adequate image for different screen sizes.

Here is a nice and simple tip with only css/html:

Ingredients

  • Transparent PNG image with the desired ratio
    (transparent-ratio-conserver.png)

  • tag

  • Different images for different view-ports (retina.jpg, desktop.jpg,
    tablet.jpg...)

The idea is to open an tag and to assign to it a transparent image (with our desired ratio). We also add class="responsive-image" that's all in HTML.

<img src="img/transparent-ratio-conserver.png" class="responsive-image">

In the CSS, we set background-size to fit the and we choose the width of our image.

.responsive-image{
    width: 100%;
    background-size: 100% 100%;
} 

and finally, we serve for every view-port the right image:

/* Retina display */
@media screen and (min-width: 1024px){
    .responsive-image{
        background-image: url('../img/retina.jpg');
    }
}
/* Desktop */
@media screen and (min-width: 980px) and (max-width: 1024px){
    .responsive-image{
        background-image: url('../img/desktop.jpg');
    }
}
/* Tablet */
@media screen and (min-width: 760px) and (max-width: 980px){
    .responsive-image{
        background-image: url('../img/tablet.jpg');
    }
}
/* Mobile HD */
@media screen and (min-width: 350px) and (max-width: 760px){
    .responsive-image{
        background-image: url('../img/mobile-hd.jpg');
    }
}
/* Mobile LD */
@media screen and (max-width: 350px){
    .responsive-image{
        background-image: url('../img/mobile-ld.jpg');
    }
} 

You can download the demo from here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文