Package org.javlo.image
Class ImageEngine
- java.lang.Object
-
- org.javlo.image.ImageEngine
-
public class ImageEngine extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static Color
DETECT_COLOR
special color to set automatic color (value is random)static boolean
DISPLAY_FOCUS
static Color
NEUTRAL_COLOR
static Color
TRANSPARENT_COLOR
static String
WEBP_CONVERTER
-
Constructor Summary
Constructors Constructor Description ImageEngine()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BufferedImage
_scale(BufferedImage img, Integer inTargetWidth, Integer inTargetHeight)
static void
addAlpha(BufferedImage img, float inAlpha)
static BufferedImage
addBlurBorder(BufferedImage image, Color bg, int width, Integer direction)
static BufferedImage
addPictureBorder(BufferedImage image, Color backgroundColors)
static BufferedImage
addTransparanceBorder(BufferedImage image, Color backgroundColors, int size, int degradedSize, int position)
static BufferedImage
applyBgColor(BufferedImage image, Color bgColor)
static BufferedImage
applyFilter(BufferedImage source, BufferedImage filter, boolean cropResize, boolean addBorder, int mt, int ml, int mr, int mb, int fzx, int fzy, boolean isFocus, Color bgColor, boolean hq)
static void
applySepiaFilter(BufferedImage img, int sepiaIntensity)
static BufferedImage
autoReduceColor(BufferedImage image)
static BufferedImage
avg(BufferedImage original)
static BufferedImage
blurring(BufferedImage img)
static BufferedImage
borderCorner(BufferedImage image, int radius, Color bg)
static BufferedImage
borderCorner(BufferedImage image, Color bg)
static BufferedImage
centerInterest(BufferedImage source, int interestX, int interestY, int minWidth, int minHeight)
static double
closeColor(BufferedImage image, Color color)
search a color inside a image.static Color
combineColor(Color color1, Color color2)
combine two color with transparency on firststatic Color
combineColor(Color c1, Color c2, float alpha)
combine two color with transparencystatic void
compressJpegFile(BufferedImage image, OutputStream out, double compressionQuality)
static BufferedImage
convertRGBAToIndexed(BufferedImage src)
static BufferedImage
createAlpha(BufferedImage image, Color bg)
replace bg color with transparencystatic BufferedImage
createLogoFramingBottomRight(BufferedImage source, BufferedImage logo)
add picture border (transform portrait (phone picture) to landscape).static BufferedImage
cropImage(BufferedImage image, int width, int height, int inX, int inY)
static BufferedImage
dashed(BufferedImage image, int size)
create transparent dash on 1 pixel on 2static BufferedImage
desaturation(BufferedImage original)
static void
drain(InputStream inputStream, OutputStream outputStream)
static BufferedImage
drawBorderCorner(BufferedImage image, int radius, Color bg, int size)
static BufferedImage
duplicateBuffuredImage(BufferedImage bi)
static boolean
equalColor(Color c1, Color c2, int tolerance)
test if two color is the same with tolerancestatic BufferedImage
flip(BufferedImage image, boolean verticaly)
static int
getColor(BufferedImage image, int x, int y)
get a color in a image, coord can be out of the image size.static int
getColor(BufferedImage image, int x, int y, Color outCol)
static int
getColorDistance(Color c1, Color c2)
the "mathematical" distance between two color.static float
getColorDistanceFactor(Color c1, Color c2)
the "mathematical" distance between two color. 1 : balck and white, 0 : same colorstatic double
getColorLight(BufferedImage image)
static int
getGoogleResultTitleSize(String text)
static Color
getTextColorOnBackground(Color backgroundColor)
return white on dark background and black otherwisestatic BufferedImage
grayscale(BufferedImage inImage)
static void
insertImage(BufferedImage source, BufferedImage target, int posx, int posy)
static boolean
isAlphaImageType(String ext)
static boolean
isDark(BufferedImage image)
return true if picture is to close of black than whitestatic BufferedImage
lightBlurring(BufferedImage img)
static BufferedImage
loadImage(File file)
static BufferedImage
loadImage(InputStream in)
static BufferedImage
loadSvg(InputStream svgStream)
static BufferedImage
luminosity(BufferedImage original)
static void
main(String[] args)
static void
mark(BufferedImage img, int x, int y)
static void
markInterest(BufferedImage source, int interestX, int interestY)
static Color
neverNullColor(Color color)
if color null return transparent.static BufferedImage
projectionImage(BufferedImage back, BufferedImage top, BufferedImage source, Polygon4 p4, float alpha, boolean crop, int interestX, int interestY)
static BufferedImage
RBGAdjust(BufferedImage image, Color adjustColor)
static byte[]
readBytesFully(InputStream in)
static BufferedImage
readWebp(File file)
static BufferedImage
removeAlpha(BufferedImage image)
static BufferedImage
removeBg(GlobalContext globalContext, BufferedImage image)
static BufferedImage
replaceAlpha(BufferedImage image, Color bg)
static BufferedImage
resize(BufferedImage source, int inWidth, int inHeight, boolean cropResize, boolean addBorder, int mt, int ml, int mr, int mb, Color bgColor, int interestX, int interestY, boolean focusZone, boolean hq)
resize a picturestatic BufferedImage
resize(BufferedImage bi, Integer width, Integer height, Color backgroundColor, boolean hq)
static BufferedImage
resizeDashed(BufferedImage image, int factor)
create transparent dashstatic BufferedImage
resizeHeight(BufferedImage bi, int height, boolean hq)
static BufferedImage
resizeHeight(BufferedImage bi, int height, int mt, int mr, int ml, int mb, Color bgColor, boolean hq)
static BufferedImage
resizeHeight(BufferedImage bi, int height, Color bgColor, boolean hq)
static BufferedImage
resizeImage(BufferedImage in, int width, int height)
static BufferedImage
resizeWidth(BufferedImage bi, int width, boolean hq)
static BufferedImage
resizeWidth(BufferedImage bi, int width, int mt, int mr, int ml, int mb, Color bgColor, boolean hq)
static BufferedImage
rotate(BufferedImage image, int angle, Color bg)
rotate the image with angle in degree. note than result can be bigger than source.static Image
scale(Image img, Integer inTargetWidth, Integer inTargetHeight, boolean hq)
static void
setColor(BufferedImage image, int x, int y, Color color)
set a color in a image, coord can be out of the image size.static void
storeImage(BufferedImage img, File file)
static void
storeImage(BufferedImage img, String ext, OutputStream outImage)
static BufferedImage
toBufferedImage(Image img, Color backgroundColor)
static BufferedImage
trim(BufferedImage image, Color color, int tolerance)
static BufferedImage
trimBottom(BufferedImage image, Color color, int tolerance)
static BufferedImage
trimLeft(BufferedImage image, Color color, int tolerance)
static BufferedImage
trimRight(BufferedImage image, Color color, int tolerance)
static BufferedImage
trimTop(BufferedImage image, Color color, int tolerance)
static BufferedImage
ultraLight(BufferedImage image)
static BufferedImage
web2(BufferedImage image, Color bgColor, int height, int separation)
static BufferedImage
zoom(BufferedImage img, double zoom, int interestX, int interestY)
-
-
-
Field Detail
-
WEBP_CONVERTER
public static String WEBP_CONVERTER
-
DISPLAY_FOCUS
public static boolean DISPLAY_FOCUS
-
NEUTRAL_COLOR
public static final Color NEUTRAL_COLOR
-
TRANSPARENT_COLOR
public static final Color TRANSPARENT_COLOR
-
DETECT_COLOR
public static final Color DETECT_COLOR
special color to set automatic color (value is random)
-
-
Method Detail
-
loadImage
public static BufferedImage loadImage(File file) throws IOException
- Throws:
IOException
-
loadImage
public static BufferedImage loadImage(InputStream in) throws IOException
- Throws:
IOException
-
drain
public static void drain(InputStream inputStream, OutputStream outputStream)
-
readBytesFully
public static byte[] readBytesFully(InputStream in)
-
readWebp
public static BufferedImage readWebp(File file) throws FileNotFoundException, IOException
- Throws:
FileNotFoundException
IOException
-
isAlphaImageType
public static boolean isAlphaImageType(String ext)
-
storeImage
public static void storeImage(BufferedImage img, File file) throws IOException
- Throws:
IOException
-
storeImage
public static void storeImage(BufferedImage img, String ext, OutputStream outImage) throws IOException
- Throws:
IOException
-
blurring
public static BufferedImage blurring(BufferedImage img)
-
loadSvg
public static BufferedImage loadSvg(InputStream svgStream) throws IOException
- Throws:
IOException
-
luminosity
public static BufferedImage luminosity(BufferedImage original)
-
avg
public static BufferedImage avg(BufferedImage original)
-
desaturation
public static BufferedImage desaturation(BufferedImage original)
-
lightBlurring
public static BufferedImage lightBlurring(BufferedImage img)
-
toBufferedImage
public static BufferedImage toBufferedImage(Image img, Color backgroundColor)
-
resize
public static BufferedImage resize(BufferedImage bi, Integer width, Integer height, Color backgroundColor, boolean hq)
-
zoom
public static BufferedImage zoom(BufferedImage img, double zoom, int interestX, int interestY)
-
scale
public static Image scale(Image img, Integer inTargetWidth, Integer inTargetHeight, boolean hq)
-
_scale
public static BufferedImage _scale(BufferedImage img, Integer inTargetWidth, Integer inTargetHeight)
-
getColor
public static int getColor(BufferedImage image, int x, int y)
get a color in a image, coord can be out of the image size.- Parameters:
image
- a standard java imagex
- if < 0 -> get 0 id > width -> get width-1y
- if < 0 -> get 0 id > length -> get length-1- Returns:
- the color of a pixel
-
setColor
public static void setColor(BufferedImage image, int x, int y, Color color)
set a color in a image, coord can be out of the image size.- Parameters:
image
- a standard java imagex
- if < 0 -> get 0 id > width -> get width-1y
- if < 0 -> get 0 id > length -> get length-1
-
neverNullColor
public static Color neverNullColor(Color color)
if color null return transparent.- Parameters:
color
-- Returns:
-
getColor
public static int getColor(BufferedImage image, int x, int y, Color outCol)
-
resizeHeight
public static BufferedImage resizeHeight(BufferedImage bi, int height, Color bgColor, boolean hq)
-
resizeWidth
public static BufferedImage resizeWidth(BufferedImage bi, int width, boolean hq)
-
resizeHeight
public static BufferedImage resizeHeight(BufferedImage bi, int height, boolean hq)
-
resizeWidth
public static BufferedImage resizeWidth(BufferedImage bi, int width, int mt, int mr, int ml, int mb, Color bgColor, boolean hq)
-
resizeHeight
public static BufferedImage resizeHeight(BufferedImage bi, int height, int mt, int mr, int ml, int mb, Color bgColor, boolean hq)
-
drawBorderCorner
public static BufferedImage drawBorderCorner(BufferedImage image, int radius, Color bg, int size)
-
borderCorner
public static BufferedImage borderCorner(BufferedImage image, int radius, Color bg)
-
RBGAdjust
public static BufferedImage RBGAdjust(BufferedImage image, Color adjustColor)
-
borderCorner
public static BufferedImage borderCorner(BufferedImage image, Color bg)
-
replaceAlpha
public static BufferedImage replaceAlpha(BufferedImage image, Color bg)
-
createAlpha
public static BufferedImage createAlpha(BufferedImage image, Color bg)
replace bg color with transparency- Parameters:
image
-bg
-- Returns:
- image with transparency
-
removeAlpha
public static BufferedImage removeAlpha(BufferedImage image)
-
applyFilter
public static BufferedImage applyFilter(BufferedImage source, BufferedImage filter, boolean cropResize, boolean addBorder, int mt, int ml, int mr, int mb, int fzx, int fzy, boolean isFocus, Color bgColor, boolean hq)
-
mark
public static final void mark(BufferedImage img, int x, int y)
-
markInterest
public static final void markInterest(BufferedImage source, int interestX, int interestY)
-
centerInterest
public static BufferedImage centerInterest(BufferedImage source, int interestX, int interestY, int minWidth, int minHeight)
-
resize
public static BufferedImage resize(BufferedImage source, int inWidth, int inHeight, boolean cropResize, boolean addBorder, int mt, int ml, int mr, int mb, Color bgColor, int interestX, int interestY, boolean focusZone, boolean hq)
resize a picture- Parameters:
source
- the source imageinWidth
- new withinHeight
- new heightcropResize
- true if image must be croped or false if image must be deformedmt
- margin topml
- margin leftmr
- margin rightmb
- margin bottombgColor
- background color (for margin and alpha)interestX
- x position of the interest zone in the pictureinterestY
- y position of the interest zone in the picture- Returns:
- a resized image
-
insertImage
public static void insertImage(BufferedImage source, BufferedImage target, int posx, int posy)
-
applyBgColor
public static BufferedImage applyBgColor(BufferedImage image, Color bgColor)
-
resizeImage
public static BufferedImage resizeImage(BufferedImage in, int width, int height) throws IOException
- Throws:
IOException
-
web2
public static BufferedImage web2(BufferedImage image, Color bgColor, int height, int separation)
-
cropImage
public static BufferedImage cropImage(BufferedImage image, int width, int height, int inX, int inY)
-
compressJpegFile
public static void compressJpegFile(BufferedImage image, OutputStream out, double compressionQuality)
-
rotate
public static BufferedImage rotate(BufferedImage image, int angle, Color bg)
rotate the image with angle in degree. note than result can be bigger than source.- Parameters:
image
-angle
-- Returns:
-
dashed
public static BufferedImage dashed(BufferedImage image, int size)
create transparent dash on 1 pixel on 2- Parameters:
image
-- Returns:
- a image width same width and same height.
-
resizeDashed
public static BufferedImage resizeDashed(BufferedImage image, int factor)
create transparent dash- Parameters:
image
-- Returns:
- a image width same width and same height.
-
grayscale
public static BufferedImage grayscale(BufferedImage inImage)
-
getColorDistance
public static int getColorDistance(Color c1, Color c2)
the "mathematical" distance between two color.- Parameters:
c1
-c2
-- Returns:
-
getColorDistanceFactor
public static float getColorDistanceFactor(Color c1, Color c2)
the "mathematical" distance between two color. 1 : balck and white, 0 : same color- Parameters:
c1
-c2
-- Returns:
-
getTextColorOnBackground
public static Color getTextColorOnBackground(Color backgroundColor)
return white on dark background and black otherwise- Parameters:
backgroundColor
-- Returns:
-
closeColor
public static double closeColor(BufferedImage image, Color color)
search a color inside a image.- Parameters:
image
-color
-- Returns:
- the distance from all pixels to color (0:no difference (all pixel are the same and is exactly the color value) 1 : max difference (image in black and color is white)).
-
applySepiaFilter
public static void applySepiaFilter(BufferedImage img, int sepiaIntensity)
- Parameters:
img
- Image to modifysepiaIntensity
- From 0-255, 30 produces nice results- Throws:
Exception
-
flip
public static BufferedImage flip(BufferedImage image, boolean verticaly)
-
equalColor
public static boolean equalColor(Color c1, Color c2, int tolerance)
test if two color is the same with tolerance- Parameters:
c1
-c2
-tolerance
- difference between two colors 0 >> 3*255- Returns:
-
trimTop
public static BufferedImage trimTop(BufferedImage image, Color color, int tolerance)
-
trimLeft
public static BufferedImage trimLeft(BufferedImage image, Color color, int tolerance)
-
trimBottom
public static BufferedImage trimBottom(BufferedImage image, Color color, int tolerance)
-
trimRight
public static BufferedImage trimRight(BufferedImage image, Color color, int tolerance)
-
trim
public static BufferedImage trim(BufferedImage image, Color color, int tolerance)
-
ultraLight
public static BufferedImage ultraLight(BufferedImage image)
-
combineColor
public static Color combineColor(Color c1, Color c2, float alpha)
combine two color with transparency- Parameters:
c1
- front colorc2
- back coloralpha
- transparency (0>1)
-
combineColor
public static Color combineColor(Color color1, Color color2)
combine two color with transparency on first- Parameters:
c1
- front colorc2
- back color
-
addAlpha
public static void addAlpha(BufferedImage img, float inAlpha)
-
duplicateBuffuredImage
public static BufferedImage duplicateBuffuredImage(BufferedImage bi)
-
projectionImage
public static BufferedImage projectionImage(BufferedImage back, BufferedImage top, BufferedImage source, Polygon4 p4, float alpha, boolean crop, int interestX, int interestY) throws Exception
- Throws:
Exception
-
isDark
public static boolean isDark(BufferedImage image)
return true if picture is to close of black than white- Parameters:
image
-- Returns:
-
createLogoFramingBottomRight
public static BufferedImage createLogoFramingBottomRight(BufferedImage source, BufferedImage logo)
add picture border (transform portrait (phone picture) to landscape).- Parameters:
image
-- Returns:
-
addPictureBorder
public static BufferedImage addPictureBorder(BufferedImage image, Color backgroundColors)
-
addTransparanceBorder
public static BufferedImage addTransparanceBorder(BufferedImage image, Color backgroundColors, int size, int degradedSize, int position)
- Parameters:
image
-backgroundColors
-size
- size of border (in %)degradedSize
- degraded size bewteen background and imageposition
- 1:top 2: right 3:bottom 4:left- Returns:
-
getColorLight
public static double getColorLight(BufferedImage image)
-
getGoogleResultTitleSize
public static int getGoogleResultTitleSize(String text)
-
autoReduceColor
public static BufferedImage autoReduceColor(BufferedImage image) throws IOException
- Throws:
IOException
-
addBlurBorder
public static BufferedImage addBlurBorder(BufferedImage image, Color bg, int width, Integer direction)
- Parameters:
image
-bg
-with
-direction
- null=all 1=top 2=right 3=bottom 4=left- Returns:
-
convertRGBAToIndexed
public static BufferedImage convertRGBAToIndexed(BufferedImage src)
-
removeBg
public static BufferedImage removeBg(GlobalContext globalContext, BufferedImage image) throws IOException
- Throws:
IOException
-
-