Subida de código
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <https://unlicense.org/>
|
||||
@@ -0,0 +1,22 @@
|
||||
import os
|
||||
import rawpy
|
||||
import cv2
|
||||
|
||||
directory = 'arw'
|
||||
|
||||
for root, _, files in os.walk(directory):
|
||||
for fname in files:
|
||||
if fname.lower().endswith('.arw'):
|
||||
in_path = os.path.join(root, fname)
|
||||
out_path = os.path.splitext(in_path)[0] + '.jpg'
|
||||
print(f'Convirtiendo {in_path} → {out_path}')
|
||||
|
||||
# Lee y procesa RAW
|
||||
with rawpy.imread(in_path) as raw:
|
||||
rgb = raw.postprocess()
|
||||
|
||||
# OpenCV usa BGR por defecto
|
||||
bgr = cv2.cvtColor(rgb, cv2.COLOR_RGB2BGR)
|
||||
|
||||
# Guarda JPG (calidad 100)
|
||||
cv2.imwrite(out_path, bgr, [int(cv2.IMWRITE_JPEG_QUALITY), 100])
|
||||
@@ -0,0 +1,12 @@
|
||||
import os, subprocess
|
||||
|
||||
directory = 'heic2'
|
||||
|
||||
for folder,subfolder,files in os.walk(directory):
|
||||
for filename in files:
|
||||
if filename.lower().endswith(".heic") or filename.lower().endswith(".HEIC"):
|
||||
print('Converting %s' % os.path.join(folder, filename))
|
||||
bashCommand = "heif-convert -q 100 \'/home/jesusjmma/proj/LogoImagenes/"+folder+"/"+filename+"\' \'/home/jesusjmma/proj/LogoImagenes/"+folder+"/"+filename.replace('.HEIC', '.jpg')+"\'"
|
||||
print(bashCommand)
|
||||
result = subprocess.run([bashCommand], shell=True)
|
||||
continue
|
||||
@@ -0,0 +1,86 @@
|
||||
import os
|
||||
import datetime
|
||||
from PIL import Image, ExifTags
|
||||
logo_ver = '/home/jesusjmma/Documents/Logos/CEEBI/CEEBI/Logo CEEBI vertical blanco.png'
|
||||
logo_hor = './logo.png'
|
||||
logo_file = logo_hor
|
||||
logoIm = Image.open(logo_file)
|
||||
initlogoWidth, initlogoHeight = logoIm.size
|
||||
logoWidth, logoHeight = initlogoWidth, initlogoHeight
|
||||
|
||||
Image.MAX_IMAGE_PIXELS = None
|
||||
|
||||
os.makedirs('conlogo', exist_ok = True)
|
||||
|
||||
def get_unique_filename(directorio, filename):
|
||||
"""
|
||||
Genera un nombre de archivo único si el archivo ya existe en el directorio especificado.
|
||||
"""
|
||||
base, extension = os.path.splitext(filename)
|
||||
counter = 1
|
||||
temp_filename = datetime.datetime.fromtimestamp(os.path.getmtime(folder+"/"+filename)).strftime('%Y%m%d_%H%M%S') + extension
|
||||
|
||||
end_dir = 'conlogo/' + folder.replace('withoutlogo/', '', 1).replace('withoutlogo', '', 1)
|
||||
|
||||
if not os.path.exists(end_dir):
|
||||
os.makedirs(end_dir)
|
||||
|
||||
base_filename = os.path.splitext(temp_filename)[0]
|
||||
new_filename = f"{base_filename}{extension}"
|
||||
|
||||
while os.path.isfile(os.path.join(end_dir, new_filename)):
|
||||
new_filename = f"{base_filename}_{counter}{extension}"
|
||||
counter += 1
|
||||
|
||||
return os.path.join(end_dir, new_filename)
|
||||
|
||||
i = 1
|
||||
|
||||
for folder,subfolder,files in os.walk('withoutlogo'):
|
||||
for filename in files:
|
||||
print(i)
|
||||
i += 1
|
||||
logoWidth, logoHeight = initlogoWidth, initlogoHeight
|
||||
|
||||
if not (filename.endswith('.png') or filename.endswith('.jpg') or filename.endswith('.jpeg') or filename.endswith('.JPEG') or filename.endswith('.JPG')) or filename == logo_file:
|
||||
continue
|
||||
|
||||
try:
|
||||
im = Image.open(folder+"/"+filename)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
continue
|
||||
try:
|
||||
for orientation in ExifTags.TAGS.keys():
|
||||
if ExifTags.TAGS[orientation] == 'Orientation':
|
||||
break
|
||||
|
||||
exif = im._getexif()
|
||||
|
||||
if exif[orientation] == 3:
|
||||
im = im.rotate(180, expand=True)
|
||||
elif exif[orientation] == 6:
|
||||
im = im.rotate(270, expand=True)
|
||||
elif exif[orientation] == 8:
|
||||
im = im.rotate(90, expand=True)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
width, height = im.size
|
||||
|
||||
sq_fit_size = int(0.35 * min(width, height))
|
||||
margen = int(0.035 * min(width, height))
|
||||
|
||||
if logoWidth > sq_fit_size or logoHeight > sq_fit_size:
|
||||
if logoWidth > logoHeight:
|
||||
logoHeight = int((sq_fit_size / logoWidth) * logoHeight)
|
||||
logoWidth = sq_fit_size
|
||||
else:
|
||||
logoWidth = int((sq_fit_size / logoHeight) * logoWidth)
|
||||
logoHeight = sq_fit_size
|
||||
logoIm = logoIm.resize((logoWidth, logoHeight))
|
||||
|
||||
im.paste(logoIm, (margen, height - logoHeight - margen), logoIm)
|
||||
|
||||
new_filename = get_unique_filename(folder, filename)
|
||||
im.save(new_filename)
|
||||
@@ -0,0 +1,12 @@
|
||||
import os, subprocess
|
||||
|
||||
directory = 'heic2'
|
||||
|
||||
for folder,subfolder,files in os.walk(directory):
|
||||
for filename in files:
|
||||
if filename.lower().endswith(".heic") or filename.lower().endswith(".HEIC"):
|
||||
print('Converting %s' % os.path.join(folder, filename))
|
||||
bashCommand = "heif-convert -q 100 \'/home/jesusjmma/proj/LogoImagenes/"+folder+"/"+filename+"\' \'/home/jesusjmma/proj/LogoImagenes/"+folder+"/"+filename.replace('.HEIC', '.jpg')+"\'"
|
||||
print(bashCommand)
|
||||
result = subprocess.run([bashCommand], shell=True)
|
||||
continue
|
||||
Reference in New Issue
Block a user