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 ColorDETECT_COLORspecial color to set automatic color (value is random)static booleanDISPLAY_FOCUSstatic ColorNEUTRAL_COLORstatic ColorTRANSPARENT_COLORstatic StringWEBP_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 voidaddAlpha(BufferedImage img, float inAlpha)static BufferedImageaddBlurBorder(BufferedImage image, Color bg, int width, Integer direction)static BufferedImageaddPictureBorder(BufferedImage image, Color backgroundColors)static BufferedImageaddTransparanceBorder(BufferedImage image, Color backgroundColors, int size, int degradedSize, int position)static BufferedImageapplyBgColor(BufferedImage image, Color bgColor)static BufferedImageapplyFilter(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 voidapplySepiaFilter(BufferedImage img, int sepiaIntensity)static BufferedImageautoReduceColor(BufferedImage image)static BufferedImageavg(BufferedImage original)static BufferedImageblurring(BufferedImage img)static BufferedImageborderCorner(BufferedImage image, int radius, Color bg)static BufferedImageborderCorner(BufferedImage image, Color bg)static BufferedImagecenterInterest(BufferedImage source, int interestX, int interestY, int minWidth, int minHeight)static doublecloseColor(BufferedImage image, Color color)search a color inside a image.static ColorcombineColor(Color color1, Color color2)combine two color with transparency on firststatic ColorcombineColor(Color c1, Color c2, float alpha)combine two color with transparencystatic voidcompressJpegFile(BufferedImage image, OutputStream out, double compressionQuality)static BufferedImageconvertRGBAToIndexed(BufferedImage src)static BufferedImagecreateAlpha(BufferedImage image, Color bg)replace bg color with transparencystatic BufferedImagecreateLogoFramingBottomRight(BufferedImage source, BufferedImage logo)add picture border (transform portrait (phone picture) to landscape).static BufferedImagecropImage(BufferedImage image, int width, int height, int inX, int inY)static BufferedImagedashed(BufferedImage image, int size)create transparent dash on 1 pixel on 2static BufferedImagedesaturation(BufferedImage original)static voiddrain(InputStream inputStream, OutputStream outputStream)static BufferedImagedrawBorderCorner(BufferedImage image, int radius, Color bg, int size)static BufferedImageduplicateBuffuredImage(BufferedImage bi)static booleanequalColor(Color c1, Color c2, int tolerance)test if two color is the same with tolerancestatic BufferedImageflip(BufferedImage image, boolean verticaly)static intgetColor(BufferedImage image, int x, int y)get a color in a image, coord can be out of the image size.static intgetColor(BufferedImage image, int x, int y, Color outCol)static intgetColorDistance(Color c1, Color c2)the "mathematical" distance between two color.static floatgetColorDistanceFactor(Color c1, Color c2)the "mathematical" distance between two color. 1 : balck and white, 0 : same colorstatic doublegetColorLight(BufferedImage image)static intgetGoogleResultTitleSize(String text)static ColorgetTextColorOnBackground(Color backgroundColor)return white on dark background and black otherwisestatic BufferedImagegrayscale(BufferedImage inImage)static voidinsertImage(BufferedImage source, BufferedImage target, int posx, int posy)static booleanisAlphaImageType(String ext)static booleanisDark(BufferedImage image)return true if picture is to close of black than whitestatic BufferedImagelightBlurring(BufferedImage img)static BufferedImageloadImage(File file)static BufferedImageloadImage(InputStream in)static BufferedImageloadSvg(InputStream svgStream)static BufferedImageluminosity(BufferedImage original)static voidmain(String[] args)static voidmark(BufferedImage img, int x, int y)static voidmarkInterest(BufferedImage source, int interestX, int interestY)static ColorneverNullColor(Color color)if color null return transparent.static BufferedImageprojectionImage(BufferedImage back, BufferedImage top, BufferedImage source, Polygon4 p4, float alpha, boolean crop, int interestX, int interestY)static BufferedImageRBGAdjust(BufferedImage image, Color adjustColor)static byte[]readBytesFully(InputStream in)static BufferedImagereadWebp(File file)static BufferedImageremoveAlpha(BufferedImage image)static BufferedImageremoveBg(GlobalContext globalContext, BufferedImage image)static BufferedImagereplaceAlpha(BufferedImage image, Color bg)static BufferedImageresize(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 BufferedImageresize(BufferedImage bi, Integer width, Integer height, Color backgroundColor, boolean hq)static BufferedImageresizeDashed(BufferedImage image, int factor)create transparent dashstatic BufferedImageresizeHeight(BufferedImage bi, int height, boolean hq)static BufferedImageresizeHeight(BufferedImage bi, int height, int mt, int mr, int ml, int mb, Color bgColor, boolean hq)static BufferedImageresizeHeight(BufferedImage bi, int height, Color bgColor, boolean hq)static BufferedImageresizeImage(BufferedImage in, int width, int height)static BufferedImageresizeWidth(BufferedImage bi, int width, boolean hq)static BufferedImageresizeWidth(BufferedImage bi, int width, int mt, int mr, int ml, int mb, Color bgColor, boolean hq)static BufferedImagerotate(BufferedImage image, int angle, Color bg)rotate the image with angle in degree. note than result can be bigger than source.static Imagescale(Image img, Integer inTargetWidth, Integer inTargetHeight, boolean hq)static voidsetColor(BufferedImage image, int x, int y, Color color)set a color in a image, coord can be out of the image size.static voidstoreImage(BufferedImage img, File file)static voidstoreImage(BufferedImage img, String ext, OutputStream outImage)static BufferedImagetoBufferedImage(Image img, Color backgroundColor)static BufferedImagetrim(BufferedImage image, Color color, int tolerance)static BufferedImagetrimBottom(BufferedImage image, Color color, int tolerance)static BufferedImagetrimLeft(BufferedImage image, Color color, int tolerance)static BufferedImagetrimRight(BufferedImage image, Color color, int tolerance)static BufferedImagetrimTop(BufferedImage image, Color color, int tolerance)static BufferedImageultraLight(BufferedImage image)static BufferedImageweb2(BufferedImage image, Color bgColor, int height, int separation)static BufferedImagezoom(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:
FileNotFoundExceptionIOException
-
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
-
-