Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated copy around Image Processing functions #325

Merged
merged 8 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* Automatically classify content and images on save
* Automatically generate alt text and image tags for images
* Automatically scan images and PDF files for embedded text and save for use in WordPress
* [Smartly crop images](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/computervision/generatethumbnail) around a region of interest identified by Computer Vision
* [Smartly crop images](https://docs.microsoft.com/en-us/rest/api/computervision/3.1/generate-thumbnail/generate-thumbnail) around a region of interest identified by Computer Vision
* Bulk classify content with [WP-CLI](https://wp-cli.org/)

| Language Processing - Tagging | Image Processing - Alt Text | Image Processing - Smart Cropping | Image Processing - Tagging |
Expand Down Expand Up @@ -121,7 +121,7 @@ Note that [Computer Vision](https://docs.microsoft.com/en-us/azure/cognitive-ser
- In the `API Key` field, enter your `KEY 1`.

#### 3. Enable specific Image Processing features
- Choose to `Automatically Caption Images`, `Automatically Tag Images`, `Enable smart cropping`, and/or `Enable OCR`.
- Choose to `Generate alt text`, `Tag images`, `Enable smart cropping`, and/or `Scan image or PDF for text`.
- For features that have thresholds or taxonomy settings, set those as well.

#### 4. Save Image or PDF file or run WP CLI command to batch classify your content
Expand Down
38 changes: 19 additions & 19 deletions includes/Classifai/Providers/Azure/ComputerVision.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ public function setup_attachment_meta_box( $post ) {
*/
public function attachment_data_meta_box( $post ) {
$settings = get_option( 'classifai_computer_vision' );
$captions = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ) ? __( 'Rescan Alt Text', 'classifai' ) : __( 'Scan Alt Text', 'classifai' );
$tags = ! empty( wp_get_object_terms( $post->ID, 'classifai-image-tags' ) ) ? __( 'Rescan Tags', 'classifai' ) : __( 'Generate Tags', 'classifai' );
$ocr = get_post_meta( $post->ID, 'classifai_computer_vision_ocr', true ) ? __( 'Rescan Text', 'classifai' ) : __( 'Scan Text', 'classifai' );
$smart_crop = get_transient( 'classifai_azure_computer_vision_smart_cropping_latest_response' ) ? __( 'Regenerate Smart Thumbnail', 'classifai' ) : __( 'Generate Smart Thumbnail', 'classifai' );
$captions = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ) ? __( 'No alt text? Rescan image', 'classifai' ) : __( 'Generate alt text', 'classifai' );
$tags = ! empty( wp_get_object_terms( $post->ID, 'classifai-image-tags' ) ) ? __( 'Rescan image for new tags', 'classifai' ) : __( 'Generate image tags', 'classifai' );
$ocr = get_post_meta( $post->ID, 'classifai_computer_vision_ocr', true ) ? __( 'Rescan for text', 'classifai' ) : __( 'Scan image for text', 'classifai' );
$smart_crop = get_transient( 'classifai_azure_computer_vision_smart_cropping_latest_response' ) ? __( 'Regenerate smart thumbnail', 'classifai' ) : __( 'Create smart thumbnail', 'classifai' );
?>
<div class="misc-publishing-actions">
<div class="misc-pub-section">
Expand Down Expand Up @@ -280,7 +280,7 @@ public function attachment_data_meta_box( $post ) {
* @param \WP_Post $post The post object.
*/
public function attachment_pdf_data_meta_box( $post ) {
$read = empty( get_the_content( null, false, $post ) ) ? __( 'Scan PDF content', 'classifai' ) : __( 'Rescan PDF content', 'classifai' );
$read = empty( get_the_content( null, false, $post ) ) ? __( 'Scan PDF for text', 'classifai' ) : __( 'Rescan PDF for text', 'classifai' );
$status = get_post_meta( $post->ID, '_classifai_azure_read_status', true );
if ( ! empty( $status['status'] ) && 'running' === $status['status'] ) {
$running = true;
Expand Down Expand Up @@ -748,7 +748,7 @@ public function setup_fields_sections() {
'label_for' => 'url',
'input_type' => 'text',
'default_value' => $default_settings['url'],
'description' => __( 'e.g. <code>https://REGION.api.cognitive.microsoft.com/</code>', 'classifai' ),
'description' => __( 'Supported protocol and hostname endpoints, e.g., <code>https://REGION.api.cognitive.microsoft.com</code> or <code>https://EXAMPLE.cognitiveservices.azure.com</code>. This can look different based on your setting choices in Azure.', 'classifai' ),
]
);
add_settings_field(
Expand All @@ -765,54 +765,54 @@ public function setup_fields_sections() {
);
add_settings_field(
'enable-image-captions',
esc_html__( 'Automatically Caption Images', 'classifai' ),
esc_html__( 'Generate alt text', 'classifai' ),
[ $this, 'render_input' ],
$this->get_option_name(),
$this->get_option_name(),
[
'label_for' => 'enable_image_captions',
'input_type' => 'checkbox',
'default_value' => $default_settings['enable_image_captions'],
'description' => __( 'Images will be captioned with alt text upon upload', 'classifai' ),
'description' => __( 'The alt text field will be filled out automatically.', 'classifai' ),
]
);
add_settings_field(
'caption-threshold',
esc_html__( 'Caption Confidence Threshold', 'classifai' ),
esc_html__( 'Alt text confidence threshold', 'classifai' ),
[ $this, 'render_input' ],
$this->get_option_name(),
$this->get_option_name(),
[
'label_for' => 'caption_threshold',
'input_type' => 'number',
'default_value' => $default_settings['caption_threshold'],
'description' => __( 'Minimum confidence score for automatically applied image captions, numeric value from 0-100. Recommended to be set to at least 75.', 'classifai' ),
'description' => __( 'Minimum confidence score for automatically added alt text, numeric value from 0-100. Recommended to be set to at least 75.', 'classifai' ),
]
);
add_settings_field(
'enable-image-tagging',
esc_html__( 'Automatically Tag Images', 'classifai' ),
esc_html__( 'Tag images', 'classifai' ),
[ $this, 'render_input' ],
$this->get_option_name(),
$this->get_option_name(),
[
'label_for' => 'enable_image_tagging',
'input_type' => 'checkbox',
'default_value' => $default_settings['enable_image_tagging'],
'description' => __( 'Images will be tagged upon upload', 'classifai' ),
'description' => __( 'Image tags will be added automatically.', 'classifai' ),
]
);
add_settings_field(
'image-tag-threshold',
esc_html__( 'Tag Confidence Threshold', 'classifai' ),
esc_html__( 'Tag confidence threshold', 'classifai' ),
[ $this, 'render_input' ],
$this->get_option_name(),
$this->get_option_name(),
[
'label_for' => 'tag_threshold',
'input_type' => 'number',
'default_value' => $default_settings['tag_threshold'],
'description' => __( 'Minimum confidence score for automatically applied image tags, numeric value from 0-100. Recommended to be set to at least 70.', 'classifai' ),
'description' => __( 'Minimum confidence score for automatically added image tags, numeric value from 0-100. Recommended to be set to at least 70.', 'classifai' ),
]
);
// What taxonomy should we tag images with?
Expand All @@ -823,7 +823,7 @@ public function setup_fields_sections() {
}
add_settings_field(
'image-tag-taxonomy',
esc_html__( 'Tag Taxonomy', 'classifai' ),
esc_html__( 'Tag taxonomy', 'classifai' ),
[ $this, 'render_select' ],
$this->get_option_name(),
$this->get_option_name(),
Expand All @@ -844,14 +844,14 @@ public function setup_fields_sections() {
'input_type' => 'checkbox',
'default_value' => $default_settings['enable_smart_cropping'],
'description' => __(
'Crop images around a region of interest identified by ComputerVision',
'ComputerVision detects and saves the most visually interesting part of your image (i.e., faces, animals, notable text).',
'classifai'
),
]
);
add_settings_field(
'enable-ocr',
esc_html__( 'Enable OCR', 'classifai' ),
esc_html__( 'Scan image or PDF for text', 'classifai' ),
[ $this, 'render_input' ],
$this->get_option_name(),
$this->get_option_name(),
Expand All @@ -860,14 +860,14 @@ public function setup_fields_sections() {
'input_type' => 'checkbox',
'default_value' => $default_settings['enable_ocr'],
'description' => __(
'Detect text in an image and store that as post content',
'OCR detects text in images (i.e., handwritten notes) or PDF files and saves that as post content.',
iamdharmesh marked this conversation as resolved.
Show resolved Hide resolved
'classifai'
),
]
);
add_settings_field(
'enable-read-pdf',
esc_html__( 'Enable Scanning PDF', 'classifai' ),
esc_html__( 'Enable scanning PDF', 'classifai' ),
[ $this, 'render_input' ],
$this->get_option_name(),
$this->get_option_name(),
Expand Down
17 changes: 9 additions & 8 deletions includes/Classifai/Services/ImageProcessing.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ public function add_rescan_button_to_media_modal( $form_fields, $post ) {
$settings = get_option( 'classifai_computer_vision' );

if ( attachment_is_pdf( $post ) && $settings && isset( $settings['enable_read_pdf'] ) && '1' === $settings['enable_read_pdf'] ) {
$read_text = empty( get_the_content( null, false, $post ) ) ? __( 'Scan', 'classifai' ) : __( 'Rescan', 'classifai' );
$status = get_post_meta( $post->ID, '_classifai_azure_read_status', true );
$read_text = empty( get_the_content( null, false, $post ) ) ? __( 'Scan', 'classifai' ) : __( 'Rescan', 'classifai' );
$status = get_post_meta( $post->ID, '_classifai_azure_read_status', true );
if ( ! empty( $status['status'] ) && 'running' === $status['status'] ) {
$html = '<button class="button secondary" disabled>' . esc_html__( 'In progress!', 'classifai' ) . '</button>';
} else {
$html = '<button class="button secondary" id="classifai-rescan-pdf" data-id="' . esc_attr( absint( $post->ID ) ) . '">' . esc_html( $read_text ) . '</button>';
}

$form_fields['rescan_pdf'] = [
'label' => __( 'Classifai Read PDF', 'classifai' ),
'label' => __( 'Scan PDF for text', 'classifai' ),
'input' => 'html',
'html' => $html,
'show_in_edit' => false,
Expand All @@ -71,33 +71,34 @@ public function add_rescan_button_to_media_modal( $form_fields, $post ) {
if ( wp_attachment_is_image( $post ) ) {
$alt_tags_text = empty( get_post_meta( $post->ID, '_wp_attachment_image_alt', true ) ) ? __( 'Generate', 'classifai' ) : __( 'Rescan', 'classifai' );
$image_tags_text = empty( wp_get_object_terms( $post->ID, 'classifai-image-tags' ) ) ? __( 'Generate', 'classifai' ) : __( 'Rescan', 'classifai' );
$ocr_text = empty( get_post_meta( $post->ID, 'classifai_computer_vision_ocr', true ) ) ? __( 'Generate', 'classifai' ) : __( 'Rescan', 'classifai' );
$ocr_text = empty( get_post_meta( $post->ID, 'classifai_computer_vision_ocr', true ) ) ? __( 'Scan', 'classifai' ) : __( 'Rescan', 'classifai' );
$smart_crop_text = empty( get_transient( 'classifai_azure_computer_vision_smart_cropping_latest_response' ) ) ? __( 'Generate', 'classifai' ) : __( 'Regenerate', 'classifai' );

$form_fields['rescan_alt_tags'] = [
'label' => __( 'Classifai Alt Tags', 'classifai' ),
'label' => __( 'Alt text', 'classifai' ),
'input' => 'html',
'html' => '<button class="button secondary" id="classifai-rescan-alt-tags" data-id="' . esc_attr( absint( $post->ID ) ) . '">' . esc_html( $alt_tags_text ) . '</button><span class="spinner" style="display:none;float:none;"></span><span class="error" style="display:none;color:#bc0b0b;padding:5px;"></span>',
'show_in_edit' => false,
];

$form_fields['rescan_captions'] = [
'label' => __( 'Classifai Image Tags', 'classifai' ),
'label' => __( 'Image tags', 'classifai' ),
'input' => 'html',
'html' => '<button class="button secondary" id="classifai-rescan-image-tags" data-id="' . esc_attr( absint( $post->ID ) ) . '">' . esc_html( $image_tags_text ) . '</button><span class="spinner" style="display:none;float:none;"></span><span class="error" style="display:none;color:#bc0b0b;padding:5px;"></span>',
'show_in_edit' => false,
];

if ( $settings && isset( $settings['enable_smart_cropping'] ) && '1' === $settings['enable_smart_cropping'] ) {
$form_fields['rescan_smart_crop'] = [
'label' => __( 'Classifai Smart Crop', 'classifai' ),
'label' => __( 'Smart thumbnail', 'classifai' ),
'input' => 'html',
'html' => '<button class="button secondary" id="classifai-rescan-smart-crop" data-id="' . esc_attr( absint( $post->ID ) ) . '">' . esc_html( $smart_crop_text ) . '</button><span class="spinner" style="display:none;float:none;"></span><span class="error" style="display:none;color:#bc0b0b;padding:5px;"></span>',
'show_in_edit' => false,
];
}

$form_fields['rescan_ocr'] = [
'label' => __( 'Detect Text', 'classifai' ),
'label' => __( 'Scan image for text', 'classifai' ),
'input' => 'html',
'html' => '<button class="button secondary" id="classifai-rescan-ocr" data-id="' . esc_attr( absint( $post->ID ) ) . '">' . esc_html( $ocr_text ) . '</button><span class="spinner" style="display:none;float:none;"></span><span class="error" style="display:none;color:#bc0b0b;padding:5px;"></span>',
'show_in_edit' => false,
Expand Down
Loading