首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何制作具有8位α的混合JPG / PNG

如何制作具有8位α的混合JPG / PNG
EN

Stack Overflow用户
提问于 2011-09-21 22:58:11
回答 1查看 425关注 0票数 0

我想在网站上放一个大的(几乎全屏幕) alpha透明图像,但我有以下问题:

  • 如果我使用JPG,大小和压缩是可以的,但是如果我使用PNG-24,则无法使其透明(100 KB)
  • -如果我使用PNG-24和http://www.8bitalpha.com/将其转换为PNG-8,那么大小就会变小,但我不能以256种颜色再现原始图形。尺寸仍然相当大(700 kB)

如果我只为透明区域创建PNG-8文件,为非透明区域创建JPG图像,我会考虑什么。用绝对的位置把东西移到适当的位置。有人做过这样的事吗?

或者另一个想法,但这是我真的没有经验的:是否有可能使用JPG图像,并将其与8位PNG中的alpha透明度结合起来?我的意思是使用JS、CSS3、画布或其他我以前从未使用过的东西?

这是我现在使用PNG-8的页面,但是它很大(700 kb),一些颜色丢失了。

http://ilhaamproject.com/sand-texture-2/

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-22 00:11:19

我以前用过同样的JPG + PNG技巧,用的是大而透明的背景图像。把你的大照片切成两种长方形:

  1. 不需要透明性(保存为JPG)的
  2. ,需要透明的(另存为PNG)

目标是获得尽可能多的图像细节保存与JPG。

接下来,您需要使用相对定位和绝对定位将所有内容重新组合起来:

代码语言:javascript
复制
<div class="bg">
    <div class="content">
        http://slipsum.com
    </div>

    <div class="section top"></div>
    <div class="section middle"></div>
    <div class="section bottom"></div>
</div>

.bg {
    width: 600px; /* width of your unsliced image */
    min-height: 800px; /* height of your unsliced image, min-height allows content to expand */
    position: relative; /* creates coordinate system */
}

/* Your site's content - make it appear above the sections */
.content {
    position: relative;
    z-index: 2;
}

/* Define the sections and their background images */
.section {
    position: absolute;
    z-index: 1;
}

.section.top {
    width: 600px;
    height: 200px;
    top: 0;
    left: 0;
    background: url(top.png) no-repeat 0 0;
}

.section.middle {
    width: 600px;
    height: 400px;
    top: 200px;
    left: 0;
    background: url(middle.jpg) no-repeat 0 0;
}

.section.bottom {
    width: 600px;
    height: 200px;
    top: 600px;
    left: 0;
    background: url(bottom.png) no-repeat 0 0;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7507731

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档