How to use the jimp.VERTICAL_ALIGN_MIDDLE function in jimp

To help you get started, we’ve selected a few jimp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xtremespb / zoia2 / modules_unused / boats / backend / apiBoatsSave.js View on Github external
const {
                            name
                        } = p;
                        if (req.body[name]) {
                            try {
                                const filename = uuid();
                                const img = await Jimp.read(req.body[name][0].data);
                                const thumb = await Jimp.read(req.body[name][0].data);
                                await fs.ensureDir(`${__dirname}/../static/cache/${id}/photos`);
                                img.scaleToFit(800, Jimp.AUTO);
                                img.quality(config.qualityThumbPic);
                                thumb.quality(config.qualityFullPic);
                                img.composite(watermark, img.bitmap.width - config.watermarkWidth, img.bitmap.height - config.watermarkHeight);
                                const imgBuffer = await img.getBufferAsync(Jimp.MIME_JPEG);
                                await fs.writeFile(`${__dirname}/../static/cache/${id}/photos/${filename}.jpg`, imgBuffer);
                                thumb.cover(config.thumbnailWidth, config.thumbnailHeight, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE); // eslint-disable-line no-bitwise
                                const thumbBuffer = await thumb.getBufferAsync(Jimp.MIME_JPEG);
                                await fs.writeFile(`${__dirname}/../static/cache/${id}/photos/tn_${filename}.jpg`, thumbBuffer);
                                picsHash[name] = filename;
                            } catch (e) {
                                req.log.error({
                                    ip: req.ip,
                                    path: req.urlData().path,
                                    query: req.urlData().query,
                                    error: e.message
                                });
                                rep.code(400)
                                    .send(JSON.stringify({
                                        statusCode: 400,
                                        errors: {
                                            default: {
                                                name: 'Error while processing images'
github Racle / Reddit2Ebook / index.js View on Github external
async function createCover() {

    // load font and our base cover image
    // we put subreddit into this image
    const font = await Jimp.loadFont(Jimp.FONT_SANS_64_BLACK);
    const image = await Jimp.read("./cover/Reddit2Ebook.jpg");

    await image.print(
        font,
        0, // x
        600, // y
        {
            text: subreddit,
            alignmentX: Jimp.HORIZONTAL_ALIGN_CENTER,
            alignmentY: Jimp.VERTICAL_ALIGN_MIDDLE
        },
        782, // maxWidth (use same width as base cover image to center correctly)
        200  // maxHeight
    )
      .quality(80) // set JPEG quality. We don't need very high quality output.
      .write("./cover/cover.jpg");

}
github afuh / pinstagram / controllers / imageControllers.js View on Github external
exports.makeAvatar = async (req, res, next) => {
  const extension = req.file.mimetype.split('/')[1];
  req.body.url = crypto.randomBytes(10).toString('hex');
  req.body.photo = `${req.body.url}.${extension}`;

  const photo = await jimp.read(req.file.buffer);
  await photo.resize(300, jimp.AUTO).quality(70);
  await photo.cover(150, 150, jimp.HORIZONTAL_ALIGN_CENTER | jimp.VERTICAL_ALIGN_MIDDLE);

  if (req.user.avatar && !req.user.avatar.includes('http')) {
    const remove = promisify(fs.unlink)
    await remove(`${__dirname}/../public/uploads/avatar/${req.user.avatar}`)
  }
  await photo.write(`./public/uploads/avatar/${req.body.photo}`);

  next();
}
github rr- / szurubooru / client / build.js View on Github external
.then(file => {
            file.resize(dim.center, Jimp.AUTO, Jimp.RESIZE_BEZIER)
                .background(0xFFFFFFFF)
                .contain(dim.w, dim.center,
                    Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE)
                .contain(dim.w, dim.h,
                    Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE)
                .write(path.join('./public/img/',
                    'apple-touch-startup-image-' + dim.w + 'x' + dim.h + '.png'));
        });
    }))
github rr- / szurubooru / client / build.js View on Github external
.then(file => {
            file.resize(dim.center, Jimp.AUTO, Jimp.RESIZE_BEZIER)
                .background(0xFFFFFFFF)
                .contain(dim.w, dim.center,
                    Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE)
                .contain(dim.w, dim.h,
                    Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE)
                .write(path.join('./public/img/',
                    'apple-touch-startup-image-' + dim.w + 'x' + dim.h + '.png'));
        });
    }))
github itgalaxy / favicons / helpers-es5.js View on Github external
resize: function resize(image, properties, offset, callback) {
                    print('Images:resize', 'Resizing image to contain in ' + properties.width + 'x' + properties.height + ' with offset ' + offset);
                    var offsetSize = offset * 2;

                    if (properties.rotate) {
                        print('Images:resize', 'Rotating image by ' + ROTATE_DEGREES);
                        image.rotate(ROTATE_DEGREES, false);
                    }

                    image.contain(properties.width - offsetSize, properties.height - offsetSize, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE);
                    return callback(null, image);
                },
                composite: function composite(canvas, image, properties, offset, maximum, callback) {
github jbeuckm / strapi-plugin-image-formats / admin / src / jimpMethodConfigs / contain.js View on Github external
const Jimp = require('jimp');

const RESIZE_MODES = [
  Jimp.HORIZONTAL_ALIGN_LEFT,
  Jimp.HORIZONTAL_ALIGN_CENTER,
  Jimp.HORIZONTAL_ALIGN_RIGHT,

  Jimp.VERTICAL_ALIGN_TOP,
  Jimp.VERTICAL_ALIGN_MIDDLE,
  Jimp.VERTICAL_ALIGN_BOTTOM
];

const FIELD_CONFIGS = {
  width: {
    type: 'integer',
    min: 1,
    max: 4096,
    required: true,
    default: 150
  },
  height: {
    type: 'integer',
    min: 1,
    max: 4096,
    required: true,
github dan335 / nimp / classes / nodes / image / Text.js View on Github external
new InputNumber(this, 0, 'Width', 'hasWidthInput'),
      new InputNumber(this, 1, 'Height', 'hasHeightInput'),
      new InputString(this, 2, 'String', 'hasStringInput')
    ];
    this.outputs = [
      new OutputImage(this, 0, 'Output'),
      new OutputNumber(this, 1, 'Width'),
      new OutputNumber(this, 2, 'Height'),
    ];

    this.hasWidth = typeof settings.hasWidth !== 'undefined' ? settings.hasWidth : false;
    this.hasHeight = typeof settings.hasHeight !== 'undefined' ? settings.hasHeight : false;
    this.width = typeof settings.width !== 'undefined' ? settings.width : 256;
    this.height = typeof settings.height !== 'undefined' ? settings.height : 256;
    this.alignmentX = typeof settings.alignmentX !== 'undefined' ? settings.alignmentX : Jimp.HORIZONTAL_ALIGN_LEFT;
    this.alignmentY = typeof settings.alignmentY !== 'undefined' ? settings.alignmentY : Jimp.VERTICAL_ALIGN_MIDDLE;
    this.string = typeof settings.string !== 'undefined' ? settings.string : 'Nimp';
    this.font = typeof settings.font !== 'undefined' ? settings.font : '/static/fonts/open-sans/open-sans-32-white/open-sans-32-white.fnt';
  }
github dan335 / nimp / classes / nodes / image / TextProperties.jsx View on Github external
<option value="/static/fonts/open-sans/open-sans-128-white/open-sans-128-white.fnt">Open Sans 128 White</option>
          
          <br><br>

          <label>Horizontal Alignment</label><br>
          <select id="alignmentXInput">
            <option value="{Jimp.HORIZONTAL_ALIGN_LEFT}">Left</option>
            <option value="{Jimp.HORIZONTAL_ALIGN_CENTER}">Center</option>
            <option value="{Jimp.HORIZONTAL_ALIGN_RIGHT}">Right</option>
          </select>
          <br><br>

          <label>Vertical Alignment</label><br>
          <select id="alignmentYInput">
            <option value="{Jimp.VERTICAL_ALIGN_TOP}">Top</option>
            <option value="{Jimp.VERTICAL_ALIGN_MIDDLE}">Middle</option>
            <option value="{Jimp.VERTICAL_ALIGN_BOTTOM}">Bottom</option>
          </select>
          <br><br>

          {this.renderWidth()}
          {this.renderHeight()}
          {this.renderRun()}
        
      
    )
  }
}
github itgalaxy / favicons / src / helpers.js View on Github external
promise = Jimp.read(nearestIcon.file).then(image =>
            image.contain(
              width,
              height,
              Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE,
              options.pixel_art &&
                width >= image.bitmap.width &&
                height >= image.bitmap.height
                ? Jimp.RESIZE_NEAREST_NEIGHBOR
                : null
            )
          );