1

I am using Django - GraphQL (Graphene/Relay) - ReactJS for my website. Before I request an image from my Django application I already know the exact size the image needs to be. I would like to resize my image on the server before sending it to the Client, this would just make more sense to me than to upload every image 10 with different sizes and then use logic to determine which one I need (doesn't it?).

I found django-imagekit but I didn't manage to find anything that would work for an application not using Django for the views, preferably something that works with GraphQL.

What is the best way to do this?

  • There's many different possible solutions to this. For sites with lots of traffic, resizing can be outsourced to a CDN. If the client code determines the image size, it's possible to pass dimensions in the url to the server. For example `/images/500x200/myimage.jpg` or `/images/mymage.jpg?w=500&h=200`. – Håken Lid Nov 21 '17 at 13:56
  • Your question is a bit too broad for Stack Overflow. Can you add a description of what exactly you are looking for. A literal query and expect result, perhaps something similar to this? http://facebook.github.io/graphql/October2016/#sec-Field-Alias – Håken Lid Nov 21 '17 at 13:58
  • Guess you are right and I guess I have to many questions. I hoped someone would have gone trough this process or someone can tell me best practices + libraries to use. Ill come back here when I have something more specific, or a solution. Thanks. – Joey van Breukelen Nov 21 '17 at 14:13
  • The best solution depends very much on circumstances. Sometimes it makes sense to pre generate a bunch of image sizes, other time you want to wait until somone requests a specific size. Also you usually would want to cache images to avoid the load and delay of constantly processing images on the server. There's also many ways to resize and crop images with various tradeoffs. – Håken Lid Nov 21 '17 at 14:22
  • I've been looking to find these trade-offs somewhere to find the best way but no luck, do you have any resources to share? – Joey van Breukelen Nov 21 '17 at 14:27
  • You could check out [sorl-thumbnail](https://github.com/jazzband/sorl-thumbnail). I don't think there's a guide on how to integrate it with graphene-python, but I think it should be quite possible to use them in combination. – Håken Lid Nov 21 '17 at 14:34

0 Answers0