Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions docs/src/content/docs/reference/components/image-helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,39 @@ Version: 1
## Actions


### Compress Image
Compress image with specified quality.

#### Properties

| Name | Type | Control Type | Description |
|:--------------:|:------------:|:--------------------:|:-------------------:|
| Image | FILE_ENTRY | FILE_ENTRY | |
| Quality | NUMBER | NUMBER | Compression quality of the image. |
| Result File Name | STRING | TEXT | Specifies the output file name for the result image. |


### Output



Type: FILE_ENTRY


#### Properties

| Type | Control Type |
|:------------:|:--------------------:|
| STRING | TEXT |
| STRING | TEXT |
| STRING | TEXT |
| STRING | TEXT |






### Crop Image
Crops an image to the specified dimensions.

Expand Down Expand Up @@ -59,6 +92,19 @@ Type: FILE_ENTRY



### Get Image Metadata
Get metadata of the image.

#### Properties

| Name | Type | Control Type | Description |
|:--------------:|:------------:|:--------------------:|:-------------------:|
| Image | FILE_ENTRY | FILE_ENTRY | |
| Result File Name | STRING | TEXT | Specifies the output file name for the result image. |




### Image to Base64
Converts image to Base64 string.

Expand Down
44 changes: 44 additions & 0 deletions docs/src/content/docs/reference/components/text-helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,50 @@ Type: BOOLEAN



### HTML to Markdown
Converts HTML to markdown.

#### Properties

| Name | Type | Control Type | Description |
|:--------------:|:------------:|:--------------------:|:-------------------:|
| HTML Content | STRING | TEXT_AREA | HTML content to be converted to markdown. |


### Output



Type: STRING







### Markdown to HTML
Converts markdown to HTML.

#### Properties

| Name | Type | Control Type | Description |
|:--------------:|:------------:|:--------------------:|:-------------------:|
| Markdown content | STRING | TEXT_AREA | Markdown content to convert to HTML. |


### Output



Type: STRING







### Replace
Replace all instances of any word, character, or phrase in text with another.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import com.bytechef.component.ComponentHandler;
import com.bytechef.component.definition.ComponentCategory;
import com.bytechef.component.definition.ComponentDefinition;
import com.bytechef.component.image.helper.action.ImageHelperCompressImageAction;
import com.bytechef.component.image.helper.action.ImageHelperCropImageAction;
import com.bytechef.component.image.helper.action.ImageHelperGetImageMetadataAction;
import com.bytechef.component.image.helper.action.ImageHelperImageToBase64Action;
import com.bytechef.component.image.helper.action.ImageHelperResizeImageAction;
import com.bytechef.component.image.helper.action.ImageHelperRotateImageAction;
Expand All @@ -39,7 +41,9 @@ public class ImageHelperComponentHandler implements ComponentHandler {
.icon("path:assets/image-helper.svg")
.categories(ComponentCategory.HELPERS)
.actions(
ImageHelperCompressImageAction.ACTION_DEFINITION,
ImageHelperCropImageAction.ACTION_DEFINITION,
ImageHelperGetImageMetadataAction.ACTION_DEFINITION,
ImageHelperImageToBase64Action.ACTION_DEFINITION,
ImageHelperResizeImageAction.ACTION_DEFINITION,
ImageHelperRotateImageAction.ACTION_DEFINITION);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright 2023-present ByteChef Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bytechef.component.image.helper.action;

import static com.bytechef.component.definition.ComponentDsl.action;
import static com.bytechef.component.definition.ComponentDsl.fileEntry;
import static com.bytechef.component.definition.ComponentDsl.number;
import static com.bytechef.component.definition.ComponentDsl.outputSchema;
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.IMAGE;
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.IMAGE_PROPERTY;
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.QUALITY;
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.RESULT_FILE_NAME;
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.RESULT_FILE_NAME_PROPERTY;

import com.bytechef.component.definition.ActionContext;
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
import com.bytechef.component.definition.FileEntry;
import com.bytechef.component.definition.Parameters;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;

/**
* @author Monika Kušter
*/
public class ImageHelperCompressImageAction {

public static final ModifiableActionDefinition ACTION_DEFINITION = action("compressImage")
.title("Compress Image")
.description("Compress image with specified quality.")
.properties(
IMAGE_PROPERTY,
number(QUALITY)
.label("Quality")
.description("Compression quality of the image.")
.minValue(0)
.maxValue(1)
.required(true),
RESULT_FILE_NAME_PROPERTY)
.output(outputSchema(fileEntry()))
.perform(ImageHelperCompressImageAction::perform);

private ImageHelperCompressImageAction() {
}

protected static FileEntry perform(
Parameters inputParameters, Parameters connectionParameters, ActionContext actionContext) throws IOException {

FileEntry imageFileEntry = inputParameters.getRequiredFileEntry(IMAGE);

BufferedImage inputImage = ImageIO.read((File) actionContext.file(file -> file.toTempFile(imageFileEntry)));
String fileExtension = imageFileEntry.getExtension();
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(fileExtension);
ImageWriter writer = writers.next();

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(byteArrayOutputStream);
writer.setOutput(imageOutputStream);

ImageWriteParam params = writer.getDefaultWriteParam();
params.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
params.setCompressionQuality(inputParameters.getRequiredFloat(QUALITY));

writer.write(null, new IIOImage(inputImage, null, null), params);

imageOutputStream.close();
writer.dispose();

InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());

return actionContext
.file(file -> file.storeContent(
inputParameters.getRequiredString(RESULT_FILE_NAME) + "." + fileExtension, inputStream));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2023-present ByteChef Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bytechef.component.image.helper.action;

import static com.bytechef.component.definition.ComponentDsl.action;
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.IMAGE;
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.IMAGE_PROPERTY;
import static com.bytechef.component.image.helper.constant.ImageHelperConstants.RESULT_FILE_NAME_PROPERTY;

import com.bytechef.component.definition.ActionContext;
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
import com.bytechef.component.definition.FileEntry;
import com.bytechef.component.definition.Parameters;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.stream.ImageInputStream;

/**
* @author Monika Kušter
*/
public class ImageHelperGetImageMetadataAction {

public static final ModifiableActionDefinition ACTION_DEFINITION = action("getImageMetadata")
.title("Get Image Metadata")
.description("Get metadata of the image.")
.properties(
IMAGE_PROPERTY,
RESULT_FILE_NAME_PROPERTY)
.output()
.perform(ImageHelperGetImageMetadataAction::perform);

private ImageHelperGetImageMetadataAction() {
}

protected static Map<String, Object> perform(
Parameters inputParameters, Parameters connectionParameters, ActionContext actionContext) throws IOException {

FileEntry imageFileEntry = inputParameters.getRequiredFileEntry(IMAGE);

File imageFile = actionContext.file(file -> file.toTempFile(imageFileEntry));
ImageInputStream iis = ImageIO.createImageInputStream(imageFile);
Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);

Map<String, Object> metadataMap = new HashMap<>();

if (readers.hasNext()) {
ImageReader reader = readers.next();
reader.setInput(iis, true);
IIOMetadata metadata = reader.getImageMetadata(0);

String[] metadataFormatNames = metadata.getMetadataFormatNames();
for (String formatName : metadataFormatNames) {
metadataMap.put(formatName, metadata.getAsTree(formatName));
}
}

return metadataMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ImageHelperConstants {
public static final String DEGREE = "degree";
public static final String HEIGHT = "height";
public static final String IMAGE = "image";
public static final String QUALITY = "quality";
public static final String RESULT_FILE_NAME = "resultFileName";
public static final String WIDTH = "width";
public static final String X_COORDINATE = "x";
Expand Down
Loading
Loading