0

I have a problem with loading externel library in Sketchup

I want to know the orginal width and height of image. But i didn't find out in Sketchup API. So i download fastimage, a library can do it. (https://github.com/sdsykes/fastimage) . I installed it by using command:

gems install fastimage

This new gem is installed in: C:\Ruby186\lib\ruby\gems\1.8 .Then i require it in my script (by following the turorial in above link) :

require 'fastimage'

But i got the error: no such file to load -- fastimage

Then i found one solution in this link :http://sketchucation.com/forums/viewtopic.php?t=29412#p257058. Create a loadpath script ,and create a linking to external library. After creating this script, put them into plugin folder in Sketchup,and run Sketchup again. But i still get the error : No such file to load.

.

Version of my ruby is 1.8.6, and when i type command : puts RUBY_VERSION in Sketchup ruby console. Its output is 1.8.6 (the same version as my ruby). I don't understand why it can not require new gem. Please help me, thanks you.

Beginner
  • 59
  • 2
  • 10

2 Answers2

1

since you use , your should specify require 'rubygems' in front of your executable, so:

require 'rubygems'
require 'fastimage'

If requiring the throws the error, that means the isn't installed in your system for current , so install it, for example as follows:

apt-get install rubygems
Малъ Скрылевъ
  • 16,187
  • 5
  • 56
  • 69
0

To get the pixel width and height of an image you use the image_width and image_height methods of the Texture object for the given Material. http://www.sketchup.com/intl/en/developer/docs/ourdoc/texture.php#image_width

That's assuming when you say "image" in the context of SketchUp you mean a texture. If you want to get the info from an Image instance you use Image.pixelwidth and Image.pixelheight. http://www.sketchup.com/intl/en/developer/docs/ourdoc/image.php#pixelwidth

On the other hand, if you're looking to inspect the size of a bitmap that isn't loaded into SketchUp it's more difficult since SketchUp ships with the Ruby 1.8 core and not the standard library. You could make a Ruby C Extension and do the work in C.

thomthom
  • 2,854
  • 1
  • 23
  • 53
  • I have to keep the original rate between the width and height of image. So i need to know original width and original height of the image for obtaining the rate when i got the full path of image. I think functions Image.pixelwidth and Image.pixelheight are not effective in this case, because we need Image object first, and we obtain it by using function entities.add_image , but this function require width parameter and height parameter of image, we just give one parameter (width or height), another parameter depends on original rate, but i hadn't known the orginal rate before. – Beginner Feb 20 '14 at 16:53
  • I read API about texture. It said that :" Remember, textures are repeatable images that "tile" when painted on a surface". But this image doesn't contain repeatable images. I have just found one way to get size of image object. It is in another topic : http://stackoverflow.com/questions/2450906/is-there-a-simple-way-to-get-image-dimensions-in-ruby (the secodary answer has 13 votes). But i am not sure about that. – Beginner Feb 20 '14 at 17:00
  • Can you describe what you are trying to do with the image in SketchUp? Do you want it as a texture or `Image` entity? The `width` and `height` arguments of `Entities.add_image` is not the pixel dimensions - they are how large you want the image in the model. – thomthom Feb 20 '14 at 20:39
  • I want it as a Image entity. I want to resize this image, but still keep the original rate between width and height of it (the rate of image before importing it into model) – Beginner Feb 21 '14 at 06:57
  • If you have an `Image` entity you would only need to transform it. Just apply a uniform transformation. If you are inserting an `Image` using `Entities.add_image` then only specify the `width` argument - the `height` is optional and will be computed automatically if omitted. – thomthom Feb 21 '14 at 12:35
  • Sorry for my explanation,maybe my problem is not clearly with you. I will ask it in another topic. Because this post is related with loading externel library. Here is my problem: http://stackoverflow.com/questions/21941422/sketchup-api-get-the-width-and-height-of-image-with-given-path – Beginner Feb 21 '14 at 17:42