コード例 #1
0
ファイル: fetch-data.js プロジェクト: cedmax/cedmax.com
const fetchImages = async (dataModel, type) => {
  if (dataModel.image) {
    const options = {
      url: `${dataModel.image}${type === "project" ? "?h=200" : ""}`,
      dest: "./public/api",
    };

    const { filename } = await download.image(options);
    const { width, height } = imageSize(filename);
    dataModel.image = filename.replace("public/", "/");
    dataModel.ratio = width / height;
    if (dataModel.image.endsWith(".svg") || type === "background") {
      delete dataModel.thumbnail;
    }
  }

  if (dataModel.gif) {
    const options = {
      url: `${dataModel.gif}`,
      dest: "./public/api",
    };

    const { filename } = await download.image(options);
    delete dataModel.thumbnail;
    dataModel.gif = filename.replace("public/", "/");
  }

  return dataModel;
};
コード例 #2
0
ファイル: index.js プロジェクト: Youthink/PasswordDict6
//下载图片
async function downloadIMG(options) {
  try {
    const { filename, image } = await download.image(options);
    console.log('第' + count + '张图片:' + filename);
    count ++;
  } catch (e) {
    throw e
  }
}
コード例 #3
0
async function filterGoodreads(data) {
  const filteredData = data.GoodreadsResponse.reviews[0].review.map(
    ({
      book: [
        {
          id: [{ _: id }],
          title: [title],
          link: [bookLink],
          image_url: [imageUrl],
          authors: [
            {
              author: [
                {
                  name: [name],
                  link: [authorLink],
                },
              ],
            },
          ],
        },
      ],
    }) => ({
      id,
      title,
      bookLink,
      imageUrl: imageUrl.replace(/(?<=\d)[s|m|l]/g, 'l'),
      name,
      authorLink,
    })
  )

  for (let index = 0; index < filteredData.length; index++) {
    const { imageUrl: url } = filteredData[index]

    if (url.includes('nophoto')) {
      continue
    }

    const imagePath = `goodreads-${md5(url)}.jpg`

    await image({
      url,
      dest: `./images/${imagePath}`,
    })

    filteredData[index].imagePath = imagePath
  }

  return filteredData
}
コード例 #4
0
ファイル: tvdb.js プロジェクト: smolleyes/StreamStudio
function downloadImages(link,target,cb) {
	const download = require('image-downloader')
	console.log('DOWNLOADING IMAGE', link, target)
	options = {
		url: 'https://www.thetvdb.com/banners/'+link,
		dest: target        // Save to /path/to/dest/photo.jpg
	  }

	  download.image(options)
		.then(({ filename, image }) => {
		  console.log('File saved to', filename)
		  cb()
		}).catch((err) => {
			console.log(err)
		  throw err
		})
}
コード例 #5
0
ファイル: index.js プロジェクト: RodinJS/vrfocus
			.then($ => {
				let gago = $(".post-tp-6-header")
					.css("background-image")
					.replace(/^url\((.*?)\)$/, "$1");
				console.log(gago);
				imageoptions.url = gago;
				download
					.image(imageoptions)
					.then(({ filename, image }) => {
						sharp(filename)
							.resize(512, 256)
							.toFile(
								`${__dirname}/img/${imageName}-big.jpg`,
								(err, info) => {
									console.log(err, info);
									sharp(filename)
										.resize(crop.width, crop.heigth, {
											centreSampling: true
										})
										.toFile(
											`${__dirname}/img/${imageName}-small.jpg`,
											(err, info) => {
												console.log(err, info);
												if (err) {
													reject(err);
												}
												resolve(info);
											}
										);
								}
							);
					})
					.catch(err => {
						console.error("img download error: ", err);
						reject(err);
					});
			})
コード例 #6
0
// --------------------
// --------------------
const dlDir = './src/images/download';

// Create the dl directory if it does not exist
if (!fs.existsSync(dlDir)) {
	fs.mkdirSync(dlDir);
}

var teamLoc = './local-storage/teams/' + team + '-team.json';
var teamData = JSON.parse(fs.readFileSync(teamLoc, 'utf8'));

for (var k=0; k < teamData.players.length; k++) {

	var id = teamData.players[k].id;
	var imageurl = "http://a.espncdn.com/combiner/i?img=/i/headshots/nfl/players/full/" + id + ".png";
	var dest = './src/images/download/' + id + '.png';

	const options = {
	  url: imageurl,
	  dest: dest
	}

	download.image(options)
	.then(({ filename, image }) => {
	    logger.info('File saved to', filename);
	}).catch((err) => {
	    logger.info('couldnt load image for id');
	})

}
コード例 #7
0
ファイル: push.js プロジェクト: sidneys/pushbullet-desktop
let convertPushToNotification = (push) => {
    logger.debug('convertPushToNotification')

    // Copy Push Object
    const decoratedPush = decoratePush(push)

    // Create Options
    const notificationOptions = {
        body: decoratedPush.body,
        icon: decoratedPush.icon,
        subtitle: decoratedPush.subtitle,
        tag: decoratedPush.iden,
        title: decoratedPush.title,
        url: decoratedPush.url
    }

    // SMS Feature Enabled?
    if (decoratedPush.type === 'sms_changed') {
        const pushbulletSmsEnabled = retrievePushbulletSmsEnabled()
        if (!pushbulletSmsEnabled) { return }
    }

    // Hide Notification Body?
    const pushbulletHideNotificationBody = retrievePushbulletHideNotificationBody()
    if (pushbulletHideNotificationBody) {
        notificationOptions.body = ''
    }

    // Enable SMS Reply?
    if (decoratedPush.type === 'sms_changed') {
        notificationOptions.hasReply = true
        notificationOptions.replyPlaceholder = 'Your SMS Reply'
    }

    // Enable Chat Reply?
    if ((decoratedPush.type === 'note' || decoratedPush.type === 'link' || decoratedPush.type === 'file') && decoratedPush.direction === 'incoming' && !!decoratedPush.sender_email) {
        notificationOptions.hasReply = true
        notificationOptions.replyPlaceholder = 'Your Chat Reply'
    }

    // Image: Create Temporary Path
    const imageUrl = notificationOptions.icon || ''
    const imageProtocol = url.parse(imageUrl).protocol
    const imageFilepathTemporary = path.join(appTemporaryDirectory, `${appName}.push.${shortid.generate()}.png`)

    // Image: Skip
    if (!imageProtocol) {
        showNotification(notificationOptions, decoratedPush)

        return
    }

    // Image: Generate from Data URL
    if (imageProtocol === 'data:') {
        resizeWriteImage(dataUriToBuffer(imageUrl), imageFilepathTemporary, notificationsIconWidth, (error, imageFilepathConverted) => {
            if (error) { return }

            notificationOptions.icon = imageFilepathConverted
            showNotification(notificationOptions, decoratedPush)
        })

        return
    }

    // Image: Download from Web
    imageDownloader.image({ url: imageUrl, dest: imageFilepathTemporary })
        .then((result) => {
            const imageFilepathDownloaded = result.filename
            const imageBuffer = result.image
            const imageType = fileType(imageBuffer)
            const isIco = icojs.isICO(imageBuffer)
            const isPng = imageType.mime === 'image/png'
            const isJpeg = imageType.mime === 'image/jpg' || imageType.mime === 'image/jpeg'

            // From .PNG
            if (isPng || isJpeg) {
                resizeWriteImage(imageBuffer, imageFilepathDownloaded, notificationsIconWidth, (error, imageFilepathConverted) => {
                    if (error) { return }

                    notificationOptions.icon = imageFilepathConverted
                    showNotification(notificationOptions, decoratedPush)
                })

                return
            }

            // From .ICO
            if (isIco) {
                icojs.parse(imageBuffer, 'image/png').then(imageList => {
                    const imageMaximum = imageList[imageList.length - 1]
                    resizeWriteImage(Buffer.from(imageMaximum.buffer), imageFilepathDownloaded, notificationsIconWidth, (error, imageFilepathConverted) => {
                        if (error) { return }

                        notificationOptions.icon = imageFilepathConverted
                        showNotification(notificationOptions, decoratedPush)
                    })
                })
            }

        })
        // Image: Fallback to App Icon
        .catch((error) => {
            logger.warn('convertPushToNotification', 'imageDownloader', error)

            showNotification(notificationOptions, decoratedPush)
        })
}