In comparison to other methods we want to * Keep PNG transparency session, db session object file, python file pointer??? file_name, string? content_type, string?? blob_base, string, ie "projects/images/" must end with "/" slash extension,
(
session,
file,
file_name,
content_type,
blob_base,
extension)
| 264 | # Maybe we do... |
| 265 | |
| 266 | def process_image_for_overlay( |
| 267 | session, |
| 268 | file, |
| 269 | file_name, |
| 270 | content_type, |
| 271 | blob_base, |
| 272 | extension): |
| 273 | """ |
| 274 | |
| 275 | In comparison to other methods we want to |
| 276 | * Keep PNG transparency |
| 277 | |
| 278 | session, db session object |
| 279 | file, python file pointer??? |
| 280 | file_name, string? |
| 281 | content_type, string?? |
| 282 | blob_base, string, ie "projects/images/" must end with "/" slash |
| 283 | extension, ?? must include "."? |
| 284 | |
| 285 | """ |
| 286 | |
| 287 | new_image = Image(original_filename = file_name) |
| 288 | session.add(new_image) |
| 289 | |
| 290 | try: |
| 291 | session.commit() |
| 292 | except: |
| 293 | session.rollback() |
| 294 | raise |
| 295 | |
| 296 | image_blob = blob_base + str(new_image.id) |
| 297 | image_blob_thumb = image_blob + "_thumb" |
| 298 | |
| 299 | image = imread(file) |
| 300 | |
| 301 | if image is None: |
| 302 | raise IOError("Could not open") |
| 303 | |
| 304 | new_image.height = image.shape[0] |
| 305 | new_image.width = image.shape[1] |
| 306 | |
| 307 | if image.shape[0] > 640 or image.shape[1] > 640: |
| 308 | ratio = min((640 / image.shape[0]), |
| 309 | (640 / image.shape[1])) |
| 310 | |
| 311 | shape_x = int(round(image.shape[0] * ratio)) |
| 312 | shape_y = int(round(image.shape[1] * ratio)) |
| 313 | |
| 314 | image = imresize(image, |
| 315 | (shape_x, shape_y)) |
| 316 | |
| 317 | # Save File |
| 318 | temp = tempfile.mkdtemp() |
| 319 | new_temp_filename = temp + "/resized" + str(extension) |
| 320 | imwrite(new_temp_filename, image) |
| 321 | new_image.height = image.shape[0] |
| 322 | new_image.width = image.shape[1] |
| 323 |
no test coverage detected