Resize Google Cloud images via request URL? - google-cloud-platform

I need a CDN of images where I can resize the image from URL parameter. So for instance if I wanted a 400px wide version I would use www.cdn.com/image-400 and if I wanted a 200px version it would be www.cdn.com/image-200
From looking at this blog post it seems Google Cloud can do this:
https://medium.com/google-cloud/uploading-resizing-and-serving-images-with-google-cloud-platform-ca9631a2c556
Im having trouble understanding the article however and i wonder if its out of date. One of links to Google's documentation says you should use instead use Google Cloud Storage https://cloud.google.com/appengine/docs/standard/python/blobstore/
I came across these 2 SO questions but they seem to give opposite answers:
Get resized images from Google cloud storage
Resize image in Google Cloud Storage
Can Google Cloud resize images based on the url? If so, then how can you do this? I have a bucket set up in Google Cloud Storage, can you use images from a bucket like this?

First of all yes, it is possible, but as the first SO answer you shared it is not directly implemented and as you noticed the process it is not as straightforward as adding =sxx to an URL of a bucket.
Therefore writing https://storage.googleapis.com/bucketname/file.jpg=sxx does NOT work.
In order to create a URL capable to support this features you have to make use of Images API for Java, in particular the getServingUrl() method (there is also the GO or Python version of it) that will generate a new URL with the very same shape of the URL contained in the article you shared.
Once you retrieved the URL making use of the API you will be able to get the resized images, quoting directly from the official documentation you will be able to add:
=sxx where xx is an integer from 0–2560 representing the length, in pixels, of the image's longest side. For example, adding =s32 resizes the image so its longest dimension is 32 pixels.
=sxx-c where xx is an integer fro
m 0–2560 representing the cropped image size in pixels, and -c tells the system to crop the image.

Related

AWS S3 filename

I’m trying to build application with backend in java that allows users to create a text with images in it (something like a a personal blog). I’m planning to store these images to s3 bucket. When uploading image files to bucket i’m hashing the original name and store the hashed one in the bucket. Images are for display purpose only, no user will be able to download them. Frontend displays these images by getting a path to them from the server. So the question is, is there any need to store original name of the image file in the database? And what are the reasons, if any, of doing so?
I guess in general it is not needed because what is more important is how these resources are used or managed in the system.
Assuming your service is something like data access (similar to google drive), I don't think it's necessary to store it in DB, unless you want to make faster search queries.

Google Vision - Batch Image Annotation, map result to request images

I'm using Google Vision to detect text in images (on my backend written in kotlin).
I want to do a batch request with multiple images from a web url but the problem I'm facing is how to know what results maps to what image in the request?
Can I rely on Google to return the result in the same order as I put them into the batch request?
Currently I do not get any information in the response that I can use to figure out to what image the annotated text belongs to. And it's important that the text can be mapped to the correct image.
If you need more information please let me know and I'll provide it to you.
The responses are in the same order as they are in the request.

Django: Insert image to PostgreSQL (PgAdmin4)

Im currently working an e-shop. So my idea is to store images with Django models in PgAdmin4. As i saw in older posts methods like bytea('D:\image.jpg') and so on just converts the string constant to its binary representation.
So my question is if there is a newer method to store the actual image, or if it is possible to grab the image via a path?
models.py
image = models.ImageField(null=True, blank=True)
PgAdmin4
INSERT INTO product_images(
id, image)
VALUES (SERIAL, ?);// how to insert image?
There are several options for keeping images. The first is to use a storage service like S3, which I recommend. You can read this article for more detailed information. I can also recommend that I have used a third party package ready to use S3 with Django. If you use this option, imagefield will keep the path in S3.
Another option is if you are using only one server, you can keep the pictures in that server's local. Again imagefield will keep the path.
If you say I want to keep it directly in the database, you can follow this link. Currently, there is no newer method for it.
But I have to say that I think using a storage service like S3 is the best way under all circumstances.

Modifying image in Active Storage cloud

I'm using Rails 5.2 and GCS as cloud service.
I'd like to give an opportunity to users to crop and rotate user's image.
User has many Images, Image has one :image_file attached
In development I use such method:
class Image
...
def rotate(degree)
image = MiniMagick::Image.new(ActiveStorage::Blob.service.send(:path_for, self.image_file.key))
image.rotate "#{degree}"
image.write(ActiveStorage::Blob.service.send(:path_for, self.image_file.key))
self.image_file.blob.analyze
end
...
end
But I can't figure out how to get to image files in cloud.
I've made it to download the file to local storage and make all the operations needed.
Now it takes only to replace (delete current and create a new one with the same name) the file in the cloud (without changing anything in the database records if possible), but I can't figure out how to do this with active storage.
At least I need to get the file name in the cloud to use just bare google-cloud-ruby
To list files stored in Cloud Storage bucket using Ruby on Rails see the code example defined here. You can also upload files to cloud storage bucket and delete files from them using Ruby on Rails.
Also since you are allowing your customers to modify their files in Cloud Storage buckets, you may consider using versioning. This will incur you additional cost but will provide reliability for your customers.
Here is the link to Ruby on Google Cloud Platform documentation which might be helpful to you.

Amazon S3 different image dimensions with query string parameters

I need to store different dimensions of an image on S3. I am new to AWS Services, so it is taking some time for me to figure out how I can accomplish this.
Say I have an image called abc.png. I want to get different versions of this image using query string parameters, i.e apc.png?s=medium for medium 400x400, and abc.png?s=large for 1200*1200. I do not want to do a preprocessing, or on the fly resizing.
Is there a way to do this on the S3 level only?
The S3 API doesn't allow selecting a different file through the query string. Put the size in the image path instead: /medium/apc.png or /apc.png/medium. Don't forget to set the content-type option to the appropriate MIME type for each S3 object, which should allow the browser to render the images correctly.
Try this service, they work with s3 as well I believe
http://cloudinary.com/