起きているエラー
Express
と gm
で画像リサイズを行おうと思っているのですが、
// $npm start // $curl localhost:3000 Error: Could not execute GraphicsMagick/ImageMagick: gm "convert" "/images/image.png" "-resize" "240x240" "+profile" "\"*\"" "/images/resize.png" this most likely means the gm/convert binaries can't be found
というエラーが起きてしまいます。バイナリが見つからないとあるところから、
誤ったファイルパス指定をしているように見えるのですが、
原因がわかりません、ご教授いただけると幸いです。
// routes/index.js const express = require('express'); const router = express.Router(); const gm = require('gm'); const imagePath = '/images/image.png'; // ここのパス指定方法間違っていますか /* GET home page. */ router.get('/', function(req, res, next) { res.render('index', { title: 'Express' }); gm(imagePath ) .resize(240, 240) .noProfile() .write('/images/resize.png', function (err) { // ここのパス指定方法間違っていますか console.log(err); }); }); module.exports = router;
├── public │ ├── images │ │ └── image.png │ ├── javascripts │ └── stylesheets │ └── style.css
追伸
このフォルダ構成、コードで試しに行ったのですが、動くのでexpress
に依存したファイルパス指定が誤っている気はしてきました。
. ├── gm.js ├── image.jpg └── resize.jpg
// gm.js const fs = require('fs') const gm = require('gm'); gm('image.jpg') .resize(240, 240) .noProfile() .write('resize.jpg', function (err) { if (!err) console.log('done'); });
$ node gm.js // done
あなたの回答
tips
プレビュー