I have 15000 photos and their sizes are 2000x2000.
I want to use them as;
blabla.com/450x600/images/blabla.jpg blabla.com/1200x0/images/blabla.jpg
how can this be possible for spaces? Is there any tool to make it?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
hi you can use Photoshop and paint tool for resizing your photo Thanks AINJ IT SERVICES PVT LTD www.ainj.in
You can use ImageMagick for this, there are hooks for most programming languages (python / ruby / php)
I would recommend Python, with the Boto3 library (official S3 library by amazon). With Python + ImageMagick + Boto3 + Spaces, you should be in business in no time.
PS: A more conventional / better (in my opinion), route for your images might be something like
“example.com/images/blahblah/450x600.jpg”
or
so you could try something like this like mariogonzalez said. this will pull from one bucket and resize them locally, and upload them to another bucket, renaming it in the process. If you want to convert the images to a few dimensions, you can just expand the script to do so.
hth
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import boto3
import os
import subprocess
import time
session = boto3.session.Session()
####################################################################
client = session.client('s3',
region_name='sfo2',
endpoint_url='https://sfo2.digitaloceanspaces.com',
aws_access_key_id='32gfeGRITgtfrYOURKEYIDGTRHtrh45gdHG',
aws_secret_access_key='FwrTUCDbQG8/QMbYOUACCESSKEYRwZg3etrHtrjrJTRuREnl84')
bucket1 = ("sourcebucket") #the bucket holding original images
bucket2 = ("emptybucket") #an empty bucket you can send the converted images to
workdirectory = ("/home/username/pics/")
resizeDimension = ("512x512")
####################################################################
uploaded = []
filelist = []
failed = []
#os.mkdir(workdirectory)
def GetNames(s3, **base_kwargs): #gets the list of images in the bucket
continuation_token = None
while True:
list_kwargs = dict(MaxKeys=1000, **base_kwargs)
if continuation_token:
list_kwargs['Marker'] = continuation_token
response = client.list_objects(**list_kwargs)
yield from response.get('Contents', [])
time.sleep(1)
if not response.get('IsTruncated'): # At the end of the list?
break
else:
continuation_token = response.get('NextMarker')
def convert(filename):
try:
print("CV",filename)
subprocess.run('convert ' + workdirectory + filename+'[0]' +' -resize ' + resizeDimension +" "+ workdirectory + resizeDimension + filename, shell=True)
except Exception as e:
failed.append(filename)
def uploadImage(filename):
if os.path.exists(workdirectory+resizeDimension+filename):
try:
print("UPLOADING :",resizeDimension+filename)
client.upload_file(workdirectory+resizeDimension+filename, # Path to local file
bucket2, # Name of Space
resizeDimension+filename)
except Exception as e:
print(e)
s = str(e)
return False
return True
try:
for file in GetNames(client, Bucket=bucket1):
filelist.append(file['Key'])
print("DL",file['Key'])
try:
with open(workdirectory+file['Key'], 'wb') as f:
client.download_fileobj(bucket1, file['Key'], f)
convert(file['Key'])
except Exception as e:
s = str(e)
print(e)
except Exception as e:
s = str(e)
print(e)
for x in filelist:
try:
uploadImage(x)
except Exception as e:
s = str(e)
print(e)
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.