0

If you look at websites like Medium, you will notice that the URL of the image controls the quality % and size of the image.

i.e. https://d262ilb51hltx0.cloudfront.net/max/1280/1*trqJ8rY4_duJtwAOJOJS6w.jpeg This image is rendered as 1280px wide and max quality.

How can I do the same thing? I host my images on Amazon s3 and I want to be able to do exactly the same thing. How?

Mcope
  • 781
  • 8
  • 22

2 Answers2

0

This is not a Javascript, but server-side question.

If you're using PHP, you can use functions of the GD library to manipulate your images. You can resize images before sending them to the client, choose JPEG quality, etc.

minipif
  • 4,756
  • 3
  • 30
  • 39
0

Pass the route parameters to server and use server side tools to process the images. You can use tools like imagemagick

If you are using php.

http://php.net/manual/en/book.imagick.php

Refer this stackoverflow question How to scale down an image on the server side with PHP?

In node there is an npm package https://www.npmjs.com/package/imagemagick

var im = require('imagemagick');
im.convert(['kittens.jpg', '-resize', '25x120', 'kittens-small.jpg'], 
function(err, stdout){
  if (err) throw err;
  console.log('stdout:', stdout);
});
Community
  • 1
  • 1
tkay
  • 1,716
  • 14
  • 18
  • Is there an example of this in Node.JS or Meteor.JS? – Mcope May 06 '15 at 00:45
  • An meteor example to use imagemagick during uploading. https://github.com/ideaq/image-uploads . check the server file https://github.com/ideaq/image-uploads/blob/master/server/server_save_file.js . He is using meteorhacks:npm package to add npm package https://www.npmjs.com/package/imagemagick to meteor. Add `"imagemagick": "0.1.3"` to package.json An example for resize `im.convert(['kittens.jpg', '-resize', '25x120', 'kittens-small.jpg'], function(err, stdout){ if (err) throw err; console.log('stdout:', stdout); });` – tkay May 06 '15 at 06:00