Created
December 18, 2018 02:28
-
-
Save lucasvinbr/c5286dcb6da9e0273810878019b82687 to your computer and use it in GitHub Desktop.
Blender: Set Image Scale
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ##### BEGIN GPL LICENSE BLOCK ##### | |
# | |
# This program is free software; you can redistribute it and/or | |
# modify it under the terms of the GNU General Public License | |
# as published by the Free Software Foundation; either version 2 | |
# of the License, or (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program; if not, write to the Free Software Foundation, | |
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
# | |
# ##### END GPL LICENSE BLOCK ##### | |
import bpy | |
bl_info = { | |
"name": "Set Image Scale", | |
"category": "Image", | |
"author": "lucasvinbr (lucasvinbr@gmail.com)", | |
"version": "0.1", | |
"location": "Image Editor > Tools > Misc > Set Image Scale", | |
"description": "It's an interface to the 'image.scale(x,y)' command: it sets the current Image's width and height. The change is lost if the image is reloaded from the source.", | |
} | |
from bpy.props import (IntProperty) | |
from bpy.types import (Operator, | |
Panel, | |
Scene | |
) | |
class ScaleImageOp(Operator): | |
bl_idname = "image.set_scale_image_operator" | |
bl_label = "Set Scale" | |
@classmethod | |
def poll(cls, context): | |
sima = context.space_data | |
return (sima and sima.image) | |
def execute(self, context): | |
sima = context.space_data | |
curScene = context.scene | |
sima.image.scale(curScene.resizeImgWidth, curScene.resizeImgHeight) | |
return {'FINISHED'} | |
class ScaleImagePanel(Panel): | |
"""Panel in the Image Tools Tab""" | |
bl_space_type = 'IMAGE_EDITOR' | |
bl_region_type = 'TOOLS' | |
bl_label = "Set Image Dimensions" | |
@classmethod | |
def poll(cls, context): | |
sima = context.space_data | |
return (sima and sima.image) | |
def draw(self, context): | |
layout = self.layout | |
curScene = context.scene | |
row = layout.row() | |
row.label(text="(Save the scaled file to keep the changes!)") | |
layout.separator() | |
row = layout.row() | |
row.prop(curScene, "resizeImgWidth") | |
row = layout.row() | |
row.prop(curScene, "resizeImgHeight") | |
row = layout.row() | |
row.operator("image.set_scale_image_operator") | |
#-------------- | |
#REGISTER\UNREGISTER | |
#-------------- | |
classes = ( | |
ScaleImagePanel, | |
ScaleImageOp | |
) | |
def register(): | |
from bpy.utils import register_class | |
for cls in classes: | |
register_class(cls) | |
Scene.resizeImgWidth = IntProperty(name="Scaled Image Width", description="The width the image will have after the scaling process.", default=256, min=1, soft_min=1) | |
Scene.resizeImgHeight = IntProperty(name="Scaled Image Height", description="The height the image will have after the scaling process.", default=256, min=1, soft_min=1) | |
def unregister(): | |
from bpy.utils import unregister_class | |
for cls in reversed(classes): | |
unregister_class(cls) | |
del Scene.resizeImgWidth | |
del Scene.resizeImgHeight | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment