|
@@ -1,4 +1,5 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
+from __future__ import division
|
|
|
from .__load__ import *
|
|
|
|
|
|
class Convert(object):
|
|
@@ -300,10 +301,24 @@ class Convert(object):
|
|
|
|
|
|
Demeter.curl(api, param, 'post')
|
|
|
|
|
|
-
|
|
|
def cut(self, info):
|
|
|
+ from pdf2jpg import pdf2jpg
|
|
|
+ from wand.image import Image
|
|
|
+ dest = info['html'] + '.photo'
|
|
|
+ result = pdf2jpg.convert_pdf2jpg(info['pdf'], dest, pages="0")
|
|
|
+ source = result[0]['output_jpgfiles'][0]
|
|
|
+ dest = info['html'] + '.jpg'
|
|
|
+ command = 'mv '+source+' ' + dest
|
|
|
+ Shell.popen(command)
|
|
|
+ target_width = 300
|
|
|
+ with Image(filename=dest) as img:
|
|
|
+ target_width, target_height = self.getSize(target_width, img.width, img.height)
|
|
|
+ img.sample(target_width, target_height)
|
|
|
+ img.save(filename=dest)
|
|
|
+
|
|
|
+ '''
|
|
|
from wand.image import Image
|
|
|
- pdf = Image(filename=info['pdf'], resolution=50)
|
|
|
+ pdf = Image(filename=source, resolution=50)
|
|
|
jpg = pdf.convert('jpg')
|
|
|
req_image = []
|
|
|
i = 0
|
|
@@ -313,11 +328,21 @@ class Convert(object):
|
|
|
req_image.append(img_page.make_blob('jpg'))
|
|
|
i = i+1
|
|
|
|
|
|
- dest = info['html']
|
|
|
for img in req_image:
|
|
|
- ff = open(dest + '.jpg','wb')
|
|
|
+ ff = open(dest, 'wb')
|
|
|
ff.write(img)
|
|
|
ff.close()
|
|
|
+ '''
|
|
|
+
|
|
|
+
|
|
|
+ def getSize(self, target_width, img_width, img_height):
|
|
|
+ if img_width > target_width:
|
|
|
+ ratio = target_width / img_width
|
|
|
+ target_height = int(ratio * img_height)
|
|
|
+ else:
|
|
|
+ target_width = img_width
|
|
|
+ target_height = img_height
|
|
|
+ return target_width, target_height
|
|
|
|
|
|
def string_switch(self, x,y,z,s=1):
|
|
|
with open(x, "r", encoding="utf-8") as f:
|