Ignore:
Timestamp:
28.04.2010 15:11:53 (2 years ago)
Author:
mhallbauer
Message:

0.1.1

  • re-implemented external methods
File:
1 edited

Legend:

Unmodified
Added
Removed
  • CMESS/mediaplayer/branches/zmsgraphic_extedit/zmsgraphic_extedit.metaobj.xml

    r986 r990  
    15171517</item> 
    15181518<item type="dictionary"><dictionary> 
    1519 <item key="custom"><![CDATA[# Example code: 
    1520  
    1521 def ZMSGraphic_extEdit_crop(): 
    1522   return "This is the external method ZMSGraphic_extEdit_crop" 
    1523 ]]></item> 
     1519<item key="custom"><![CDATA[from time import localtime, strftime 
     1520from PIL import Image 
     1521from cStringIO import StringIO 
     1522import os.path 
     1523 
     1524def ZMSGraphic_extEdit_crop(dest_folder, source_id, coords, dest_id = None, unique_filename = False): 
     1525        if (dest_folder is not None): 
     1526                if (not source_id in dest_folder.objectIds()): 
     1527                        raise 'ZMSGraphic_extEdit_crop: can\'t find source-image' 
     1528                 
     1529                temp_source = getattr(dest_folder, source_id) 
     1530                temp_source = StringIO(str(temp_source.data)) 
     1531                 
     1532                temp_image = Image.open(temp_source) 
     1533                temp_image = temp_image.convert('RGB') 
     1534                temp_thumb = temp_image.crop(coords) 
     1535                temp_image_size = temp_thumb.size 
     1536         
     1537                temp_dest = StringIO() 
     1538                temp_thumb.save(temp_dest, "JPEG")  
     1539                temp_dest.seek(0) 
     1540                 
     1541                temp_path, temp_ext = os.path.splitext(source_id) 
     1542                temp_dest_id = (dest_id is None) and temp_path or dest_id 
     1543                if (unique_filename): 
     1544                        temp_dest_id += '_%s'%strftime('%Y%m%d%H%M%S', localtime()) 
     1545                temp_dest_id = temp_path + '_thumb.jpg' 
     1546                 
     1547                if (temp_dest_id in dest_folder.objectIds()): 
     1548                        dest_folder.manage_delObjects(temp_dest_id) 
     1549                 
     1550                dest_folder.manage_addImage(temp_dest_id, temp_dest) 
     1551                 
     1552                temp_result = temp_dest_id 
     1553                temp_result = (temp_dest_id, temp_image_size[0], temp_image_size[1]) 
     1554        else: 
     1555                temp_result = None 
     1556                 
     1557        return temp_result]]></item> 
    15241558<item key="id"><![CDATA[ZMSGraphic_extEdit_crop]]></item> 
    15251559<item key="mandatory" type="int">0</item> 
     
    15351569import os.path 
    15361570 
    1537 def ZMSGraphic_extEdit_resize(dest_folder, source_id, max_width, max_height = None, replace_source = False): 
     1571def ZMSGraphic_extEdit_resize(dest_folder, source_id, max_width, max_height = None, dest_id = None, replace_source = False): 
    15381572        if (dest_folder is not None): 
    15391573                if (not source_id in dest_folder.objectIds()): 
     
    15561590                 
    15571591                temp_path, temp_ext = os.path.splitext(source_id) 
    1558                 temp_dest_id = temp_path 
     1592                temp_dest_id = (dest_id is None) and temp_path or dest_id 
    15591593                if (not replace_source): 
    15601594                        temp_dest_id += '_preview' 
     
    15911625# @param methods list of FLIP_LEFT_RIGHT (0), FLIP_TOP_BOTTOM (1), ROTATE_90 (2), ROTATE_180 (3) or ROTATE_270 (4) 
    15921626 
    1593 def ZMSGraphic_extEdit_transpose(dest_folder, source_id, methods, replace_source = False, unique_filename = False): 
     1627def ZMSGraphic_extEdit_transpose(dest_folder, source_id, methods, replace_source = False, dest_id = None, unique_filename = False): 
    15941628        if (dest_folder is not None): 
    15951629                if (not source_id in dest_folder.objectIds()): 
     
    16051639                temp_image                      = temp_image.convert('RGB') 
    16061640                for one_method in methods: 
    1607                         print (str(one_method)) 
    16081641                        temp_image              = temp_image.transpose(one_method) 
    16091642                temp_image_size = temp_image.size 
     
    16141647                 
    16151648                temp_path, temp_ext = os.path.splitext(source_id) 
    1616                 temp_dest_id = temp_path 
     1649                temp_dest_id = (dest_id is None) and temp_path or dest_id 
    16171650                if (not replace_source): 
    16181651                        temp_dest_id += '_preview' 
     
    16201653                        temp_dest_id += '_%s'%strftime('%Y%m%d%H%M%S', localtime()) 
    16211654                temp_dest_id += '.jpg' 
    1622                  
    1623                 print (temp_dest_id)  
    16241655                 
    16251656                if (replace_source): 
     
    20972128<item key="name"><![CDATA[com.zms.zmsgraphic_extedit]]></item> 
    20982129<item key="package"/> 
    2099 <item key="revision"><![CDATA[0.1.0]]></item> 
     2130<item key="revision"><![CDATA[0.1.1]]></item> 
    21002131<item key="type"><![CDATA[ZMSPackage]]></item> 
    21012132</dictionary> 
Note: See TracChangeset for help on using the changeset viewer.