Exemple #1
0
 def run(self, mainframe, values=None):
     from config import card_folder
     from os.path import join, isfile
     from math import ceil
     rescale = values['Try to Rescale ?']
     path = mainframe.GetCurrentSelectedPath()
     if not path:
         return
     img = wx.Image(
         join(card_folder.decode('cp1252'), path.decode('cp1252')))
     w, h = float(img.GetWidth()), float(img.GetHeight())
     fw, fh = mainframe.fitting_size
     width_ratio = w / fw
     height_ratio = h / fh
     if rescale:
         width_ratio = int(round(width_ratio))
         height_ratio = int(round(height_ratio))
         #If one size is smaller tahn the fitting size, take fitting size as minimum
         if width_ratio == 0: width_ratio = 1
         if height_ratio == 0: height_ratio = 1
         img = img.Rescale(fw * width_ratio, fh * height_ratio)
     else:
         width_ratio = int(ceil(width_ratio))
         height_ratio = int(ceil(height_ratio))
     for wr in range(width_ratio):
         for hr in range(height_ratio):
             rect = wx.Rect(wr * fw, hr * fh, min(fw, w - wr * fw),
                            min(fh, h - hr * fh))
             simg = img.GetSubImage(rect)
             #Save the small one
             simg.SaveFile(
                 join(card_folder.decode('cp1252'),
                      'split_%d_%d.jpg' % (wr, hr)), wx.BITMAP_TYPE_JPEG)
             #Add the cards
             mainframe.AddCard(cardPath='split_%d_%d.jpg' % (wr, hr), qt=1)
Exemple #2
0
 def run(self,mainframe,values=None):
     from config import card_folder
     from os.path import join,isfile
     from math import ceil
     rescale=values['Try to Rescale ?']
     path=mainframe.GetCurrentSelectedPath()
     if not path:
         return
     img=wx.Image(join(card_folder.decode('cp1252'),path.decode('cp1252')))
     w,h=float(img.GetWidth()),float(img.GetHeight())
     fw,fh=mainframe.fitting_size
     width_ratio=w/fw
     height_ratio=h/fh
     if rescale:
         width_ratio=int(round(width_ratio))
         height_ratio=int(round(height_ratio))
         #If one size is smaller tahn the fitting size, take fitting size as minimum
         if width_ratio==0:width_ratio=1
         if height_ratio==0:height_ratio=1
         img=img.Rescale(fw*width_ratio,fh*height_ratio)
     else:
         width_ratio=int(ceil(width_ratio))
         height_ratio=int(ceil(height_ratio))
     for wr in range(width_ratio):
         for hr in range(height_ratio):
             rect=wx.Rect(wr*fw,hr*fh,min(fw,w-wr*fw),min(fh,h-hr*fh))
             simg=img.GetSubImage(rect)
             #Save the small one
             simg.SaveFile(join(card_folder.decode('cp1252'),'split_%d_%d.jpg'%(wr,hr)),wx.BITMAP_TYPE_JPEG)
             #Add the cards
             mainframe.AddCard(cardPath='split_%d_%d.jpg'%(wr,hr),qt=1)
Exemple #3
0
 def process ( self ,dc,values):
     import wx
     bmp=dc.GetAsBitmap()
     img=wx.ImageFromBitmap(bmp)
     w,h=img.GetSize().Get()
     
     #now with bdirect image cropping
     from config import card_folder
     from os.path import join,isfile
     from __main__ import  frame as mainframe
     path=mainframe.GetCurrentSelectedPath()        
     if not path:
         return
     img=wx.Image(join(card_folder.decode('cp1252'),path.decode('cp1252')))
     w,h=float(img.GetWidth()),float(img.GetHeight())
             
     def check(x,value=None):
         if x.endswith('%'):
             return value* int(x[:-1])/100
         else:
             return int(x)
     x0=check(values['x0'],w)
     y0=check(values['y0'],h)
     x1=check(values['x1'],w)
     y1=check(values['y1'],h)
     rect=wx.Rect(x0,y0,min(w,x1-x0),min(h,y1-y0))
     simg=img.GetSubImage(rect)
     
     simg.Rescale(*dc.GetSizeTuple())
     bmp=wx.BitmapFromImage(simg)
     dc.DrawBitmap(bmp,0,0)
Exemple #4
0
 def run(self,mainframe,values=None):
     from config import card_folder
     from os.path import join,isfile
     path=mainframe.GetCurrentSelectedPath()        
     if not path:
         return
     img=wx.Image(join(card_folder.decode('cp1252'),path.decode('cp1252')))
     w,h=float(img.GetWidth()),float(img.GetHeight())
     #Keep the old fitting size
     fw,fh=mainframe.fitting_size
     #I know this is mestup ! do not want to dfix it now
     numcol=values['Num Row']
     numrow=values['Num Col']
     percentage=values['Save as percentage ?']
     fw,fh=mainframe.fitting_size
     ending=''
     if percentage:
         fw,fh=100,100
         ending='%'
     stepw=fh/numcol
     steph=fw/numrow
     for j in range(numcol):
         for i in range(numrow):
             _vs={'x0':str(i*steph)+ending,'y0':str(j*stepw)+ending,'x1':str((i+1)*steph)+ending,'y1':str((j+1)*stepw)+ending}
             mainframe.AddCard(cardPath=path,qt=1,template='Subsplit Template',values=_vs)
Exemple #5
0
 def run(self, mainframe, values=None):
     from config import card_folder
     from os.path import join, isfile
     path = mainframe.GetCurrentSelectedPath()
     if not path:
         return
     img = wx.Image(
         join(card_folder.decode('cp1252'), path.decode('cp1252')))
     w, h = float(img.GetWidth()), float(img.GetHeight())
     #Keep the old fitting size
     fw, fh = mainframe.fitting_size
     #I know this is mestup ! do not want to dfix it now
     numcol = values['Num Row']
     numrow = values['Num Col']
     percentage = values['Save as percentage ?']
     fw, fh = mainframe.fitting_size
     ending = ''
     if percentage:
         fw, fh = 100, 100
         ending = '%'
     stepw = fh / numcol
     steph = fw / numrow
     for j in range(numcol):
         for i in range(numrow):
             _vs = {
                 'x0': str(i * steph) + ending,
                 'y0': str(j * stepw) + ending,
                 'x1': str((i + 1) * steph) + ending,
                 'y1': str((j + 1) * stepw) + ending
             }
             mainframe.AddCard(cardPath=path,
                               qt=1,
                               template='Subsplit Template',
                               values=_vs)
Exemple #6
0
    def process(self, dc, values):
        import wx
        bmp = dc.GetAsBitmap()
        img = wx.ImageFromBitmap(bmp)
        w, h = img.GetSize().Get()

        #now with bdirect image cropping
        from config import card_folder
        from os.path import join, isfile
        from __main__ import frame as mainframe
        path = mainframe.GetCurrentSelectedPath()
        if not path:
            return
        img = wx.Image(
            join(card_folder.decode('cp1252'), path.decode('cp1252')))
        w, h = float(img.GetWidth()), float(img.GetHeight())

        def check(x, value=None):
            if x.endswith('%'):
                return value * int(x[:-1]) / 100
            else:
                return int(x)

        x0 = check(values['x0'], w)
        y0 = check(values['y0'], h)
        x1 = check(values['x1'], w)
        y1 = check(values['y1'], h)
        rect = wx.Rect(x0, y0, min(w, x1 - x0), min(h, y1 - y0))
        simg = img.GetSubImage(rect)

        simg.Rescale(*dc.GetSizeTuple())
        bmp = wx.BitmapFromImage(simg)
        dc.DrawBitmap(bmp, 0, 0)
Exemple #7
0
    def run(self, mainframe, values=None):
        from config import card_folder
        from os.path import join, isfile
        from math import sqrt
        if not values:
            size_length = 2 * 118.1
            split = False
        else:
            size_length = values['Dice Length (in cm)'] * 118.1
            split = values['Split Selected Image?']
        if split:
            #Take the selected image, split in 6 in order to obtain 6 squares
            path = mainframe.GetCurrentSelectedPath()
            if not path:
                return
            img = wx.Image(
                join(card_folder.decode('cp1252'), path.decode('cp1252')))
            w, h = img.GetWidth(), img.GetHeight()
            w = float(w)
            h = float(h)
            nblines = int(round(6 * h / w))
            for j in range(nblines):
                for i in range(6):
                    rect = wx.Rect(i * w / 6, j * h / nblines, w / 6,
                                   h / nblines)
                    simg = img.GetSubImage(rect)
                    #Save the small one
                    simg.SaveFile(
                        join(card_folder.decode('cp1252'),
                             'ori_sub_%d_%d.jpg' % (i, j)),
                        wx.BITMAP_TYPE_JPEG)
                    #Add the cards
                    mainframe.AddCard(cardPath="ori_sub_%d_%d.jpg" % (i, j),
                                      qt=1,
                                      template=mainframe.
                                      templates['Origami Dice Template'].name)

        w = h = int(sqrt(2) * 2 * size_length)
        mainframe.fitting_size = (w, h)
        mainframe.fit.Value = "%sx%s" % (w, h)
Exemple #8
0
    def run(self,mainframe,values=None):
        from config import card_folder
        from os.path import join,isfile
        from math import sqrt
        if not values:
            size_length=2*118.1
            split=False
        else:
            size_length=values['Dice Length (in cm)'] * 118.1
            split=values['Split Selected Image?']
        if split:
            #Take the selected image, split in 6 in order to obtain 6 squares           
            path=mainframe.GetCurrentSelectedPath()
            if not path:
                return
            img=wx.Image(join(card_folder.decode('cp1252'),path.decode('cp1252')))
            w,h=img.GetWidth(),img.GetHeight()
            w=float(w)
            h=float(h)
            nblines=int(round(6*h/w))
            for j in range(nblines):
                for i in range(6):
                    rect=wx.Rect(i*w/6,j*h/nblines,w/6,h/nblines)
                    simg=img.GetSubImage(rect)
                    #Save the small one
                    simg.SaveFile(join(card_folder.decode('cp1252'),'ori_sub_%d_%d.jpg'%(i,j) ),  wx.BITMAP_TYPE_JPEG)
                    #Add the cards
                    mainframe.AddCard(
                            cardPath="ori_sub_%d_%d.jpg"%(i,j),
                            qt=1,
                            template=mainframe.templates['Origami Dice Template'].name
                    )

        w=h=int(sqrt(2) * 2 * size_length)
        mainframe.fitting_size=(w,h)
        mainframe.fit.Value="%sx%s"%(w,h)