@@ -32,6 +32,8 @@ module Squib
|
||||
# @option opts crop_corner_y_radius [Integer] (0): y radius for rounded corners of cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts crop_width [Integer] (:native): Width of the cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts crop_height [Integer] (:native): Height of the cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts flip_horiztonal [Boolean] (false): Flip this image about its center horizontally (i.e. left becomes right and vice versa).
|
||||
# @option opts flip_vertical [Boolean] (false): Flip this image about its center verticall (i.e. top becomes bottom and vice versa).
|
||||
# @return [nil] Returns nil
|
||||
# @api public
|
||||
def png(opts = {})
|
||||
@@ -79,6 +81,8 @@ module Squib
|
||||
# @option opts crop_corner_y_radius [Integer] (0): y radius for rounded corners of cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts crop_width [Integer] (:native): Width of the cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts crop_height [Integer] (:native): Height of the cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts flip_horiztonal [Boolean] (false): Flip this image about its center horizontally (i.e. left becomes right and vice versa).
|
||||
# @option opts flip_vertical [Boolean] (false): Flip this image about its center verticall (i.e. top becomes bottom and vice versa).
|
||||
# @return [nil] Returns nil
|
||||
# @api public
|
||||
def svg(opts = {})
|
||||
|
||||
@@ -20,6 +20,8 @@ module Squib
|
||||
crop_corner_radius: nil,
|
||||
crop_corner_x_radius: 0,
|
||||
crop_corner_y_radius: 0,
|
||||
flip_vertical: false,
|
||||
flip_horizontal: false,
|
||||
}
|
||||
end
|
||||
|
||||
@@ -28,7 +30,7 @@ module Squib
|
||||
end
|
||||
|
||||
def self.params_with_units
|
||||
parameters.keys # all of them
|
||||
parameters.keys - [:flip_vertical, :flip_horizontal]
|
||||
end
|
||||
|
||||
def validate_crop_width(arg, _i)
|
||||
|
||||
@@ -94,6 +94,18 @@ module Squib
|
||||
translate(-x, -y)
|
||||
end
|
||||
|
||||
# Flip either vertical or horizontal depending
|
||||
# From the cairo website: http://cairographics.org/matrix_transform/
|
||||
# cairo.Matrix(fx, 0, 0,
|
||||
# fy, cx*(1-fx), cy*(fy-1))
|
||||
# fx/fy = 1 means 'no flip', fx/fy = -1 are used for horizontal/vertical flip
|
||||
def flip(vertical, horizontal, x, y)
|
||||
v = vertical ? -1.0 : 1.0
|
||||
h = horizontal ? -1.0 : 1.0
|
||||
transform Cairo::Matrix.new(v, 0.0, 0.0,
|
||||
h, x*(1-v), y*(1-h))
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,15 +20,15 @@ module Squib
|
||||
png = Squib.cache_load_image(file)
|
||||
use_cairo do |cc|
|
||||
cc.translate(box.x, box.y)
|
||||
if box.width != :native || box.height != :native
|
||||
box.width = png.width.to_f if box.width == :native
|
||||
box.height = png.height.to_f if box.height == :native
|
||||
box.width = png.width.to_f * box.height.to_f / png.height.to_f if box.width == :scale
|
||||
box.height = png.height.to_f * box.width.to_f / png.width.to_f if box.height == :scale
|
||||
Squib.logger.warn "PNG scaling results in aliasing."
|
||||
cc.scale(box.width.to_f / png.width.to_f, box.height.to_f / png.height.to_f)
|
||||
end
|
||||
Squib.logger.warn "PNG scaling results in aliasing." if box.width != :native || box.height != :native
|
||||
box.width = png.width.to_f if box.width == :native
|
||||
box.height = png.height.to_f if box.height == :native
|
||||
box.width = png.width.to_f * box.height.to_f / png.height.to_f if box.width == :scale
|
||||
box.height = png.height.to_f * box.width.to_f / png.width.to_f if box.height == :scale
|
||||
cc.scale(box.width.to_f / png.width.to_f, box.height.to_f / png.height.to_f)
|
||||
|
||||
cc.rotate(trans.angle)
|
||||
cc.flip(trans.flip_vertical, trans.flip_horizontal, box.width / 2, box.height / 2)
|
||||
cc.translate(-box.x, -box.y)
|
||||
|
||||
trans.crop_width = png.width.to_f if trans.crop_width == :native
|
||||
@@ -37,6 +37,7 @@ module Squib
|
||||
cc.clip
|
||||
cc.translate(-trans.crop_x, -trans.crop_y)
|
||||
|
||||
|
||||
cc.set_source(png, box.x, box.y)
|
||||
cc.operator = paint.blend unless paint.blend == :none
|
||||
if paint.mask.empty?
|
||||
@@ -64,6 +65,7 @@ module Squib
|
||||
scale_height = box.height.to_f / svg.height.to_f
|
||||
use_cairo do |cc|
|
||||
cc.translate(box.x, box.y)
|
||||
cc.flip(trans.flip_vertical, trans.flip_horizontal, box.width / 2, box.height / 2)
|
||||
cc.rotate(trans.angle)
|
||||
cc.scale(scale_width, scale_height)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user