- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在研究一个系统来旋转上传的图像。该算法的工作原理如下:
1) User uploads a jpeg. It gets saved as a PNG
2) Link to the temp png is returned to the user.
3) The user can click 90left,90right, or type in N degrees to rotate
4) The png is opened using
$image = imagecreatefrompng("./fileHERE");
5) The png is rotated using
$imageRotated = imagerotate($image,$degrees,0);
6) The png is saved and the link returned to the user.
7) If the user wishes to rotate more go back to step 3 operating on the newly
saved temporary PNG,
else the changes are commited and the final image is saved as a jpeg.
这在左右旋转 90 度时效果很好。用户可以无限旋转多次而不会降低质量。问题是当用户尝试旋转 20 度(或其他一些非 90 的倍数)时。旋转 20 度时,图像会轻微旋转,并形成一个黑框来填充需要填充的区域。由于图像(带有黑框)被保存为 png,下一次旋转 20 度会将图像(带有黑框)再旋转 20 度并形成另一个黑框来弥补松弛。长话短说,如果你这样做到 360 度,你将在一个非常小的剩余图像周围有一个大黑框。即使您放大并裁剪掉黑框,也会出现明显的质量损失。
有什么方法可以避免黑匣子? (服务器没有安装imagick)
最佳答案
始终存储未修改的源文件,并且在旋转时,使用原始源文件旋转度数。所以 20 度 + 20 度,意味着将源旋转 40 度。
使用
打开 png$image = imagecreatefromjpeg("./source.jpg");
png 被旋转了...
// If this is the first time, there is no rotation data, set it up
if(!isset($_SESSION["degrees"])) $_SESSION["degrees"] = 0;
// Apply the new rotation
$_SESSION["degrees"] += $degrees;
// Rotate the image
$rotated = imagerotate($image, $_SESSION["degrees"], 0);
// Save the image, DO NOT MODIFY THE SOURCE FILE!
imagejpeg($rotated, "./last.jpg");
// Output the image
header("Content-Type: image/jpeg");
imagejpeg($rotated);
如果用户希望旋转更多,则返回第 3 步,否则 last.jpg 将被视为最终的并且 $_SESSION["degrees"]
参数被销毁。
关于php - 无损图像旋转与 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12897104/
我正在寻找一个专门用于进一步压缩Jpeg而不改变图像的库。我找到了PackJpeg,但它不提供任何源代码,并且您不允许在商业上使用它。 最佳答案 在PackJPG page上,有一个指向JPEG Op
对于我的视频隐写项目(java),我需要将连续的 PNG 编码到电影文件中。我尝试了xuggler,但我得到了压缩。(由于隐藏在png图像的LSB中的数据在下次我从视频中提取帧时会丢失) 因为我需要稍
我想根据一个或多个模型的属性来过滤 Backbone 集合。我已经阅读了这个问题,我注意到讨论最多的解决方案是简单地使用 this.where({"applicationType": applicat
有没有办法使用 Python 或使用命令行无损将 PDF 旋转 90 度? 我正在寻找真正的旋转,而不仅仅是在 PDF 中添加“/ROTATE 90”,因为之后我必须通过 Hylafax 发送 PDF
我目前正在尝试在 FFMPEG 上使用 H264 对 RGB24 文件进行无损压缩。但是,H264 压缩(RGB24 -> YUV444)中使用的色彩空间转换已被证明是有损的(我猜测是由于量化误差)。
我目前正在处理无损 JPEG 文件(不是 JPEG-LS)。很难找到任何文件来测试我的应用程序。 特别是我需要包含重置间隔标记、多个 DC 霍夫曼表、多个场景或注释标记的文件。 你知道我在哪里可以找到
我正在尝试无损压缩图像,为了利用规律性,我想将图像从 RGB 转换为 Y'CbCr。 (我所说的 RGB 和 Y'CbCr 的具体细节在这里并不重要;RGB 数据由三个字节组成,我有三个字节来存储结果
我正在尝试仅使用 JavaScript 和 HTML5 自己创建 DICOM 查看器。最近几天我一直在研究这个项目,现在我成功解析了我需要的所有文本信息,并且我还可以正确读取和显示未压缩的灰度和 RG
Google 的 PageSpeed 工具告诉我优化我的 PNG 图像,这些图像在 Photoshop 中保存用于网络。在研究了无损 PNG 压缩选项后,我下载了 ImageOptim 并通过它放了一
我需要压缩视频流以通过网络将其从 C++ 库传输到 Java 平台 (Android) 并在那里解压缩。要求如下: 该库必须可用于 Android 平台和 C++(或者,2 个使用通用格式的独立库)
使用 ffmpeg h264(无损)编码/解码视频的见解 所以我在编码部分做了一些工作,用 264 编码一个 avi,但是 VLC 不会播放它,但是 Totem 会。解码同一个文件证明很麻烦。 (我想
我是一名优秀的程序员,十分优秀!