def fix_dir(self,sdir,fn): if fn.endswith(('.png','.jpg','.jpeg','.gif')): path = os.path.join(sdir + '/', fn) with open(path,'rb') as r: read_data = r.read() dim = get_image_size(read_data) return fn + '\t' + 'w:'+str(dim.get('width'))+" h:"+str(dim.get('height')) return fn
def run(self, edit): view = self.view sel = view.sel()[0].a if not 'string' in view.scope_name(sel): return scope = view.extract_scope(sel-1) tag_scope = view.extract_scope(scope.a-1) region = sublime.Region(sel, scope.b-1) view.erase(edit, region) path = view.substr(view.extract_scope(sel-1)) if path.startswith(("'","\"","(")): path = path[1:-1] path = path[path.rfind('/'):] full_path = self.this_dir + path if '<img' in view.substr(tag_scope) and path.endswith(('.png','.jpg','.jpeg','.gif')): with open(full_path,'rb') as r: read_data = r.read() dim = get_image_size(read_data) self.insert_dimension(edit,dim,'width',tag_scope) self.insert_dimension(edit,dim,'height',tag_scope)