Ubuntu
3 years ago
7 changed files with 96 additions and 46 deletions
File diff suppressed because one or more lines are too long
@ -1,8 +1,54 @@ |
|||
# Copyright (c) 2021, Hard n Soft Technologies Pvt Ltd and contributors |
|||
# For license information, please see license.txt |
|||
|
|||
# import frappe |
|||
import frappe |
|||
from frappe.model.document import Document |
|||
from PIL import Image |
|||
from frappe.utils import cstr |
|||
import os |
|||
|
|||
class Systems(Document): |
|||
pass |
|||
def validate(self): |
|||
pass |
|||
@frappe.whitelist() |
|||
def image_size(image,doc): |
|||
current_db_name = frappe.conf.get("db_name") |
|||
doc = frappe.get_doc("Systems",doc) |
|||
site_name = cstr(frappe.local.site) |
|||
file_path = "/home/ubuntu/frappe-bench/sites/"+site_name +"/public" + image |
|||
size = os.path.getsize(file_path) |
|||
img = Image.open(file_path) |
|||
width = img.width |
|||
height = img.height |
|||
if(width > 510 and height > 510): |
|||
frappe.db.sql("""delete from `tabFile` where file_url = %s""",image) |
|||
frappe.db.commit() |
|||
a = frappe.db.sql("""select name from {0}.`tabFile` where file_url = '{1}'""".format(current_db_name,image)) |
|||
frappe.msgprint(str(a)) |
|||
return image |
|||
if(size > 10485760 ): |
|||
frappe.db.sql("""delete from `tabFile` where file_url = %s""",image) |
|||
frappe.db.commit() |
|||
return size |
|||
|
|||
@frappe.whitelist() |
|||
def image_size(image,doc): |
|||
current_db_name = frappe.conf.get("db_name") |
|||
site_name = cstr(frappe.local.site) |
|||
file_path = "/home/ubuntu/frappe-bench/sites/"+site_name +"/public" + image |
|||
size = os.path.getsize(file_path) |
|||
img = Image.open(file_path) |
|||
width = img.width |
|||
height = img.height |
|||
|
|||
# if size > 10485760000: |
|||
# frappe.db.sql("""delete from {0}.`tabFile` where file_url = '{1}'""".format(current_db_name,image)) |
|||
# frappe.db.commit() |
|||
# return size |
|||
|
|||
if (width > 2048 or height > 1080): |
|||
frappe.db.sql("""delete from {0}.`tabFile` where file_url = '{1}'""".format(current_db_name,image)) |
|||
frappe.db.commit() |
|||
return image |
|||
|
|||
|
Loading…
Reference in new issue