Module: Asposeimagingjava::CropImages

Defined in:
lib/asposeimagingjava/images/cropimages.rb

Instance Method Summary collapse

Instance Method Details

#crop_by_rectangleObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/asposeimagingjava/images/cropimages.rb', line 39

def crop_by_rectangle()
    data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'

    # Load an existing image (of type bmp) in an instance of Image class
    image = Rjb::import('com.aspose.imaging.Image').load(data_dir + "test.jpg")

    # Before cropping, the image should be cached for better performance
    if !image.isCached()
        image.cacheData()
    end

    # Create an instance of Rectangle class with desired size
    rectangle = Rjb::import('com.aspose.imaging.Rectangle').new(10, 10, 100, 100)

    # Perform the crop operation on object of Rectangle class
    image.crop(rectangle)

    # Save the image to disk
    image.save(data_dir + "crop_by_rectangle.jpg")

    # Display Status.
    puts "Cropped image by rectangle successfully!"
end

#crop_by_shiftsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/asposeimagingjava/images/cropimages.rb', line 11

def crop_by_shifts()
    data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'

    # Load an existing image (of type bmp) in an instance of Image class
    image = Rjb::import('com.aspose.imaging.Image').load(data_dir + "test.jpg")

    # Before cropping, the image should be cached for better performance
    if !image.isCached()
        image.cacheData()
    end

    # Define shift values for all four sides
    left_shift = 10
    right_shift = 10
    top_shift = 10
    bottom_shift = 10

    # Based on the shift values, apply the cropping on image
    # Crop method will shift the image bounds toward the center of image
    image.crop(left_shift, right_shift, top_shift, bottom_shift)

    # Save the image to disk
    image.save(data_dir + "CropByShifts.jpg")

    # Display Status.
    puts "Cropped image by shifts successfully!"
end

#initializeObject



3
4
5
6
7
8
9
# File 'lib/asposeimagingjava/images/cropimages.rb', line 3

def initialize()
    # Cropping by Shifts
    crop_by_shifts()

    # Cropping by Rectangle
    crop_by_rectangle()
end