Skip to content
Snippets Groups Projects
Commit 7bbcb446 authored by Josef Olsson's avatar Josef Olsson
Browse files

Autosize added images

parent 6b77ba90
No related branches found
No related tags found
1 merge request!91Resolve "Upload pictures"
This commit is part of merge request !91. Comments created here will be created in the context of that merge request.
...@@ -140,10 +140,6 @@ const SlideSettings: React.FC = () => { ...@@ -140,10 +140,6 @@ const SlideSettings: React.FC = () => {
.catch(console.log) .catch(console.log)
} }
//const images = [{ id: 'image1', name: 'Wallgren.png' }]
//const [images, setimages] = useState(imageList)
const updateSlideType = async () => { const updateSlideType = async () => {
closeSlideTypeDialog() closeSlideTypeDialog()
if (activeSlide) { if (activeSlide) {
...@@ -253,8 +249,6 @@ const SlideSettings: React.FC = () => { ...@@ -253,8 +249,6 @@ const SlideSettings: React.FC = () => {
const imageData = { const imageData = {
x: 0, x: 0,
y: 0, y: 0,
w: 400,
h: 400,
data: { data: {
media_id: media.id, media_id: media.id,
filename: media.filename, filename: media.filename,
......
...@@ -2,10 +2,15 @@ ...@@ -2,10 +2,15 @@
This file contains functionality to add data to the database. This file contains functionality to add data to the database.
""" """
import os
from PIL import Image
from flask.globals import current_app
from sqlalchemy.orm import relation
from sqlalchemy.orm.session import sessionmaker from sqlalchemy.orm.session import sessionmaker
from app.apis.media import PHOTO_PATH
import app.core.http_codes as codes import app.core.http_codes as codes
from app.core import db from app.core import db
from app.database.controller import utils from app.database.controller import get, search, utils
from app.database.models import ( from app.database.models import (
Blacklist, Blacklist,
City, City,
...@@ -98,6 +103,20 @@ def component(type_id, slide_id, data, x=0, y=0, w=0, h=0): ...@@ -98,6 +103,20 @@ def component(type_id, slide_id, data, x=0, y=0, w=0, h=0):
provided size and data . provided size and data .
""" """
if type_id == 2: # 2 is image
item_image = get.one(Media, data["media_id"])
filename = item_image.filename
path = os.path.join(PHOTO_PATH, filename)
with Image.open(path) as im:
h = im.height
w = im.width
largest = max(w, h)
if largest > 600:
ratio = 600 / largest
w *= ratio
h *= ratio
return db_add(Component(slide_id, type_id, data, x, y, w, h)) return db_add(Component(slide_id, type_id, data, x, y, w, h))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment