我需要使用Java程序减小图像的大小(而不是宽度和高度).他们有什么好的API可用吗?
我需要将大小从1MB减小到大约50kb - 100 kb.当然,决议会减少,但这无关紧要.
在我的一个应用程序中,我正在使用下面的代码片段将上传的图像复制到目录中.它工作正常,但复制大图像(> 2MB)需要比理想时间更多的时间,我真的不需要这么大的图像,所以,我正在寻找一种方法来调整图像的大小.如何使用PHP实现这一目标?
<?php
$uploadDirectory = 'images/0001/';
$randomNumber = rand(0, 99999);
$filename = basename($_FILES['userfile']['name']);
$filePath = $uploadDirectory.md5($randomNumber.$filename);
// Check if the file was sent through HTTP POST.
if (is_uploaded_file($_FILES['userfile']['tmp_name']) == true) {
// Validate the file size, accept files under 5 MB (~5e+6 bytes).
if ($_FILES['userfile']['size'] <= 5000000) {
// Move the file to the path specified.
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $filePath) == true) {
// ...
}
}
}
?>
Run Code Online (Sandbox Code Playgroud) 我有大约50-60个pdf文件(图像),每个文件大1.5MB.现在我不想在我的论文中有如此大的pdf文件,因为这会使下载,阅读和打印成为后方的痛苦.所以我尝试使用ghostscript执行以下操作:
gs \
-dNOPAUSE -dBATCH \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS="/screen" \
-sOutputFile=output.pdf \
L_2lambda_max_1wl_E0_1_zg.pdf
Run Code Online (Sandbox Code Playgroud)
但是,现在我的1.4MB pdf是1.5MB大.
我做错了什么?有什么办法可以检查pdf文件的分辨率吗?我只需要300dpi的图像,所以有人会建议使用convert
更改分辨率,或者有一些我可以改变图像分辨率(减少它)gs
,因为我使用时图像非常粗糙convert
我如何使用转换:
convert \
-units PixelsPerInch \
~/Desktop/L_2lambda_max_1wl_E0_1_zg.pdf \
-density 600 \
~/Desktop/output.pdf
Run Code Online (Sandbox Code Playgroud)
http://dl.dropbox.com/u/13223318/L_2lambda_max_1wl_E0_1_zg.pdf
我是OpenCV的新手,我正在研究Canny的边缘检测教程.我正在研究如何调整mat
刚创建的大小.代码是这样的:
src = imread( impath );
...
dst.create( src.size(), src.type() );
Run Code Online (Sandbox Code Playgroud)
现在我尝试用这个来调整垫子的大小:
resize(dst, dst, dst.size(), 50, 50, INTER_CUBIC);
Run Code Online (Sandbox Code Playgroud)
但它似乎没有改变任何东西.
我的疑惑是两个:
1:我做以及调用resize()
后create()
?
2:我如何指定尺寸mat
?
我的目标是调整图像大小,如果不清楚的话
我正在尝试AWS S3
使用nodejs 从存储桶中获取图像,将其大小调整为4种不同的大小,然后将其保存回同一个存储桶,但保存到一个文件夹中,该文件夹又包含4个文件夹,每个文件夹用于新的大小.
当我运行该函数时,我收到以下错误:
Unable to resize devimageresize/diavelBlack.jpg and upload to / due to an error: Error: Stream yields empty buffer
Run Code Online (Sandbox Code Playgroud)
我对nodejs比较新,我不确定我是否正确编写代码.导致此错误的原因是什么?
这是我的代码:
// dependencies
var async = require('async');
var AWS = require('aws-sdk');
var gm = require('gm');
var util = require('util');
// get reference to S3 client
var s3 = new AWS.S3();
exports.handler = function(event, context) {
// Read options from the event.
console.log("Reading options from event:\n", util.inspect(event, {depth: 5}));
var srcBucket = event.Records[0].s3.bucket.name;
var srcKey = event.Records[0].s3.object.key; …
Run Code Online (Sandbox Code Playgroud) 我想在TensorFlow中做一个简单的双线性调整(不一定是整数因子).例如,从(32,3,64,64)张量开始,我想要一个(32,3,96,96)张量,其中每个64x64使用双线性插值重新调整1.5倍.最好的方法是什么?
我希望这能支持任意因子> 1,而不仅仅是1.5.
注意:每个64x64上的操作与操作相同skimage.transform.rescale (scale=1.5, order=1)
.
结果tf.image.resize_bilinear
与之完全不同cv2.resize
.
我发现这有点麻烦.设置align_corners=True
并不总是合理的,因为四个角并不总是固定在角落里.那么无论如何要让它更"对称"吗?
代码重现:
import tensorflow as tf
import numpy as np
import cv2
np.set_printoptions(precision=3)
resize_shape = (10, 10)
a = np.ones((1, 2, 2, 1), dtype=np.float32)
a[0, 0, 0, 0] = 5.0
a[0, 1, 1, 0] = 5.0
b = tf.constant(a, dtype=tf.float32)
c = tf.image.resize_bilinear(b, resize_shape)
with tf.Session() as sess:
np_c = sess.run(c)
print np_c[0, :, :, 0]
print cv2.resize(a[0], resize_shape, interpolation=cv2.INTER_LINEAR)
Run Code Online (Sandbox Code Playgroud)
获得的结果:
# tf.image.resize_bilinear
[[ 5. 4.2 3.4 2.6 1.8 1. 1. 1. 1. …
Run Code Online (Sandbox Code Playgroud) 你们有没有知道一个很好的php类我可以用来从远程源下载图像,将其重新调整为120x120并用我选择的文件名保存?
所以基本上我会在"http://www.site.com/image.jpg"上有一个图像保存到我的网络服务器"/images/myChosenName.jpg"为120x120像素.
谢谢
我正在使用WinForms.在我的表单中,我有一个pictureBox
(设置为normal mode
),下一个和上一个按钮.我想快速调整大小和加载多页TIF图像.当我转到多页TIF图像的下一页时,每次将图像绘制到图像时都会遇到延迟pictureBox
.图像的平均速度大约需要800毫秒.我希望页面在100毫秒内加载.
我希望像IrfanView一样快速处理大型TIF图像.IrfanView是一个小型图像查看应用程序.如果您下载IrfanView,您可以看到性能有多快.目前我有另一个解决方案,我使用多线程后台工作程序将TIF页面加载到一个数组然后我缩小它.这种方法最初需要一些时间,但这里的目标是不必等待.
有没有办法提高Graphics.DrawImage
.NET中大图像的性能?
g.DrawImage(img,0,0,width,height); //此行导致延迟"800毫秒,具体取决于您的计算机"
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Tif_Preformance_Question
{
public partial class Form1 : Form
{
int counter = -1;
int frameCount = 0;
Stopwatch s = new Stopwatch();
Image img;
Image[] images;
public Form1()
{
InitializeComponent();
}
private void btn_Open_Click(object …
Run Code Online (Sandbox Code Playgroud) 我尝试使用 Xcode 11.4 和 iOS 13.4 在支持 SwiftUI 的应用程序中包含 pdf。但是,当我调整 pdf 大小时,它的边缘会变得粗糙。我已经包含了 pdf 的两个版本:一个大 pdf ( icon.pdf
) 和一个小 pdf ( icon_small.pdf
)。当我调整大小时,icon.pdf
它会开始边缘,而icon_small.pdf
边缘会变得平滑。该问题也适用于我尝试过的所有其他 pdf。
这是我的代码:
struct ContentView: View {
var body: some View {
VStack {
Spacer()
Text("icon.pdf:")
Image("icon")
.resizable()
.renderingMode(.template)
.aspectRatio(contentMode: .fit)
.frame(width: 27.0, height: 27.0)
Spacer()
Text("icon_small.pdf:")
Image("icon_small")
Spacer()
}
}
}
Run Code Online (Sandbox Code Playgroud)
双方icon.pdf
并icon_small.pdf
具有下列资产设置:
pdf 可在此处获得:
image-resizing ×10
image ×4
opencv ×2
pdf ×2
php ×2
tensorflow ×2
.net ×1
api ×1
c# ×1
c++ ×1
ghostscript ×1
java ×1
node.js ×1
python ×1
resolution ×1
size ×1
swiftui ×1
winforms ×1