如何使用ColdFusion缩放图像而不会丢失分辨率? [英] How can I scale an image with ColdFusion without losing resolution?

查看:239
本文介绍了如何使用ColdFusion缩放图像而不会丢失分辨率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

服务器配置




  • Windows Server 2003 b $ b
  • IIS 6

  • ColdFusion 8标准版

  • > Java Version 6 Update 18



我有一个ColdFusion应用程序,允许用户上传将添加到现有PDF。当图片添加到PDF时,它们必须适合最小/最大高度和宽度,因此上传的图片需要缩放以适应。



例如,假设给定图片的最小高度和宽度为100x100,最大高度和宽度为200x200,用户上传的图片为500x1000。我使用下面的逻辑来缩放图像,而不会将图像(它保持其原始形状)扭曲到100x200。对于小于最小值的图片,它会按比例放大(在上面的示例中,50x50的图片将放大到100x100)。



我注意到的问题是当ColdFusion使用其内置函数缩放图像时,它将分辨率降低到72dpi。有没有办法防止这种分辨率的损失,因为图像被添加到需要打印质量的PDF?



这里是[缩小]代码我正在使用缩放图片:

 < cfscript> 
imagePath =/uploads/image.tif;
scaledWidth = 100;
scaledHeight = 100;
scaledImage = ImageNew(imagePath);
ImageSetAntialiasing(scaledImage,on);
ImageScaleToFit(scaledImage,scaledWidth,scaledHeight);
< / cfscript>


解决方案

我想你可能想跳过缩放图像所有并将原始图像添加到PDF文档。然后有什么PDF创建工具,你正在使用调整大小,并将图像放置在文档画布上。类似于在HTML中的图像上将宽度和高度设置为除了其原始分辨率之外的其他值。我不必像你描述的那样将图像添加到PDF文档中,但是这篇文章可能指向正确的方向:



使用ColdFusion和iText将动态图像添加到PDF


Server Config:

  • Windows Server 2003
  • IIS 6
  • ColdFusion 8 Standard Edition
  • Java Version 6 Update 18

I have a ColdFusion application that allows users to upload images that will be added to an existing PDF. When the images are added to the PDF, they have to fit within a minimum/maximum height and width, so the uploaded image needs to be scaled to fit.

For instance, let's say the minimum height and width for a given image is 100x100, and the maximum height and width is 200x200, and the user uploads an image that is 500x1000. I use the logic below to scale that image down without skewing the image (it keeps its original shape) to 100x200. For an image smaller than the minimum, it is scaled up (in the example above, a 50x50 image would be scaled up to 100x100).

The problem I'm noticing is that when ColdFusion scales the image using its built-in functions, it reduces the resolution to 72dpi. Is there a way to prevent this loss of resolution, as the images are being added to PDFs which need to be print-quality?

Here's the [scaled-down] code I'm using to scale the images:

<cfscript>
    imagePath = "/uploads/image.tif";
    scaledWidth = 100;
    scaledHeight = 100;
    scaledImage = ImageNew(imagePath);
    ImageSetAntialiasing(scaledImage, "on");
    ImageScaleToFit(scaledImage, scaledWidth, scaledHeight);
</cfscript>

解决方案

I think you may want to skip scaling the image at all and add the original image to the pdf document. Then have whatever pdf creation tool you are using "resize" and position the image on the document canvas. Similar to setting width and height on images in html to something other than its native resolution. I have not had to add images to PDFs docs like you described but this post might point you in the right direction:

Adding a dynamic image to a PDF using ColdFusion and iText

这篇关于如何使用ColdFusion缩放图像而不会丢失分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆