我有四张256x256像素:a.jpg,b.jpg,c.jpg和d.jpg.我想将它们合并在一起以产生2x2马赛克图像.生成的图像也应为256x256像素.
像这样:
+---+---+
| a | b |
+---+---+
| c | d |
+---+---+
Run Code Online (Sandbox Code Playgroud)
使用普通的GraphicsMagick和命令行可以完成
gm convert -background black \
-page +0+0 a.jpg \
-page +256+0 b.jpg \
-page +0+256 c.jpg \
-page +256+256 d.jpg \
-minify \
-mosaic output.jpg
Run Code Online (Sandbox Code Playgroud)
但问题是,如何在Node.js中使用GraphicsMagick来做到这一点?
gm('a.jpg')
.append('b.jpg')
.append('c.jpg')
.append('d.jpg')
.write('output.jpg', function (err) {})
// Produces 1x4 mosaic with dimensions 256x1024 px, not what I wanted
Run Code Online (Sandbox Code Playgroud) 如何使用GM Node.js'gm composite -gravity center change_image_url base_image_url'?
如何调用gm().command()和/ gm().in()或gm().out()实现上述目标?
ImageMagick创建了一些相当大的PNG.GraphicsMagick要好得多,但我仍然在寻找与convert一起使用的最佳选项,以获得最小的文件大小png.
我这里有一个带有小文件大小的大png,并通过IM转换传递我无法达到该文件大小,更不用说让它变小了.通过GM转换我可以稍微小一些,但我正在寻找改进,一般来说我遇到的任何图像.
gm convert -quality 95 a_png.png gm.png
convert -quality 95 -depth 8 a_png.png im.png
gm identify *
a_png.png PNG 2560x2048+0+0 PseudoClass 256c 8-bit 60.1K 0.000u 0:01
gm.png[1] PNG 2560x2048+0+0 PseudoClass 256c 8-bit 60.0K 0.000u 0:01
im.png[2] PNG 2560x2048+0+0 DirectClass 8-bit 130.2K 0.000u 0:01
Run Code Online (Sandbox Code Playgroud)
什么转换选项产生最小的PNG文件大小?
(是的,我熟悉OptiPNG,PNGOUT和Pngcrush.但是我正在寻找一些可以在我正好碰上的每个*nix盒子上使用的东西.)
我之前有一个与ImageMagick一起使用的rmagick gem安装.从禁用OpenMP的源安装ImageMagick.这种安装工作没有任何障碍.但是我试图卸载rmagick和ImageMagick,以便我可以使用适用于GraphicsMagick的版本.
所以我从源代码安装了GraphicsMagick并再次禁用了OpenMP功能.但是,当我安装rmagick时,我得到以下内容:
Building native extensions. This could take a while...
ERROR: Error installing rmagick-2.13.1.gem:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb --build-opts --with-graphics-magick
checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... yes
Warning: Found a partial ImageMagick installation. Your operating system likely has some built-in ImageMagick libraries but not all of ImageMagick. This will most likely cause problems at both compile and runtime.
Found partial installation at: /usr
checking for ImageMagick …Run Code Online (Sandbox Code Playgroud) 我正在寻找如何在Meteor Up Docker上安装Graphicsmagick.
我找到了这个解决方案(在docker中访问二进制文件)但我无法工作,我在哪里放这些行start.sh?
meteorDockerId=docker ps | grep meteorhacks/meteord:base | awk '{print $1}'
docker exec $meteorDockerId apt-get install graphicsmagick -y
Run Code Online (Sandbox Code Playgroud)
那是我的start.sh:
#!/bin/bash
APPNAME=instagatas
APP_PATH=/opt/$APPNAME
BUNDLE_PATH=$APP_PATH/current
ENV_FILE=$APP_PATH/config/env.list
PORT=80
USE_LOCAL_MONGO=0
# remove previous version of the app, if exists
docker rm -f $APPNAME
# remove frontend container if exists
docker rm -f $APPNAME-frontend
set -e
docker pull meteorhacks/meteord:base
if [ "$USE_LOCAL_MONGO" == "1" ]; then
docker run \
-d \
--restart=always \
--publish=$PORT:80 \
--volume=$BUNDLE_PATH:/bundle \ …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用此pecl命令为GraphicsMagick安装PHP API :
sudo pecl install channel://pecl.php.net/gmagick-1.0.10b1
Run Code Online (Sandbox Code Playgroud)
在安装过程中我被问到这个问题:
Please provide the prefix of GraphicsMagick installation [autodetect]
Run Code Online (Sandbox Code Playgroud)
我不知道如何回答这个问题,如果我按Enter键进行自动检测,则安装失败.
checking whether to enable the gmagick extension... yes, shared
checking GraphicsMagick configuration program... configure: error: not found. Please provide a path to GraphicsMagick-config program.
ERROR: `/tmp/pear/temp/gmagick/configure --with-gmagick' failed
Run Code Online (Sandbox Code Playgroud)
我正在使用ubuntu服务器,有谁知道如何安装这个程序?
我正在使用SailsJS(测试版).我试图找到一种方法来使用graphicsmagick在SailsJS-beta中使用Skipper解析的流来调整Skipper函数之前调整图像大小req.file('inputName').upload().
我的目标是拍摄我原始的大图像,并在上传之前调整大小.Sails beta引入了Skipper文件解析器,这些解析器文档很少(至少我不理解它).请帮我了解如何在上传前调整图片大小.
这工作(我的控制器动作中的代码):
req.file('fileName').upload('storedImage.png', function(err, files){
// File is now uploaded to storedImage.png
});
Run Code Online (Sandbox Code Playgroud)
我想要的是:
// Read the file stream into a file upload
var stream = req.file('fileName');
gm(stream).resize(200, 200).write('storedImage.png', function(err){
// File is now resized to 200x200 px and uploaded to storedImage.png
});
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何正确获取流req.file('fileName')以将其发送到gm?
我这样做
gm(jpgName).setFormat('jpg')
.resize(160,158)
.compress('JPEG')
.write(fs.createWriteStream(jpgName),function(err){
if(err){
console.log(err,jpgName);
res.send(400);
}else{
console.log('file formated to jpg' + jpgName);
Run Code Online (Sandbox Code Playgroud)
我明白了
{ [Error: Command failed: gm convert: Empty input file (/home/ubuntu/node/uploads/icon.jpg). ] code: 1, signal: null }
Run Code Online (Sandbox Code Playgroud)
如果我在此处写入的第一行之前停止代码,然后查看该文件,则它具有文件长度.如果我让这个过程发生(错误输出)然后查看文件,那么它的大小为0字节.
我也试过这个:
fs.stat(jpgName, function (err, stats) {
console.log('file size:',stats.size);
gm(jpgName).setFormat('jpg')
.resize(160,158)
.compress('JPEG')
.write(fs.createWriteStream(jpgName),function(err){
if(err){
console.log('console.log error writing jpg file',err,jpgName);
fs.unlink(jpgName);
callback(400);
return;
}else{//...
Run Code Online (Sandbox Code Playgroud)
而且我得到了一个文件大小,所以我知道在开始这个过程之前它并不是空的.
编辑:我现在开始这个过程,form.on('end')所以我可以确定整个上传过程已经完成.
function formatProfileImage(req,form,file,callback){
console.log('formatting profile image');
var ext = file.name.split('.')[1].toLowerCase();
var name = encodeURIComponent(file.name.split('.')[0].toLowerCase());
var smallName = form.uploadDir+"/"+"small_"+name+".jpg";
var jpgName = …Run Code Online (Sandbox Code Playgroud) 如何tiff用g4压缩编写文件?
imwrite(string("compressed.tif"), res);
Run Code Online (Sandbox Code Playgroud)
这是在发送数据之前处理图像数据,write_fax()因此不需要进一步处理(已注释掉处理write_fax)..但输出文件完全是黑色的..
res.convertTo(res, CV_32FC1, 1.0 / 255.0);
res = 1.0 - res;
res = Img + res;
threshold(res, res, 0.85, 1, THRESH_BINARY);
// sends data to `write_fax()`
Run Code Online (Sandbox Code Playgroud)
/*
* Compile
* # g++ txtbin.cpp -o txtbin -ltiff `pkg-config opencv --cflags --libs`
*
* Run
* # ./txtbin input.jpg output.png
*/
#include "string"
#include "fstream"
#include "/usr/include/opencv2/opencv.hpp"
#include "/usr/include/boost/tuple/tuple.hpp"
#include "/usr/include/x86_64-linux-gnu/tiff.h"
#include "/usr/include/x86_64-linux-gnu/tiffio.h"
#include <stdint.h>
#include <vector>
#include <stdexcept>
#include …Run Code Online (Sandbox Code Playgroud) 我已使用Node GM在后端将上传的图像转换为渐进式图像并存储在文件中。之后,我想在前端显示转换后的渐进图像。我的问题是当我渲染该图像时,它逐行渲染。但是与正常图像相比,这些渐进图像首先被加载。
但是我想将图像从模糊加载到正常。我怎样才能做到这一点?
在前端,我使用这样的HTML编写了代码。
<html>
<head></head>
<body>
<h1>Hello</h1>
<img style="width:50%" src="https://www.dropbox.com/s/p57ik1kl04k1iax/progressive3.jpg?raw=1" />
<img style="width:30%" src="https://www.dropbox.com/s/3nnc03tfwxrpu5q/Porsche-GT2-4K-UHD-Wallpaper.jpg?raw=1" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud) graphicsmagick ×10
node.js ×4
image ×2
imagemagick ×2
javascript ×2
c++ ×1
composite ×1
compression ×1
docker ×1
formidable ×1
frontend ×1
html ×1
libtiff ×1
linux ×1
meteor ×1
meteor-up ×1
opencv ×1
pear ×1
php ×1
png ×1
rmagick ×1
ruby ×1
rubygems ×1
sails.js ×1
skipper ×1