1 Crop Hints

1.1 crophints_get (array $options)

Load the Crop Hint for the image.

Crop Hint

Parameters

type default description
post_id * int null

Specifies the post ID of an image uploaded to the media library.

type string null

Specifies the type of the Crop Hint.

  • 'auto' OR 'manual'
  • If not specified, 'manual' will take precedence if the Manual Crop Hint exists, and then 'auto' will be selected.
force_analyze boolean false

Specifies whether to perform immediate extraction if the image does not have the Auto Crop Hint.

  • Extracting an autocrop hint takes more time than loading the stored data because it accesses the API and analyzes the image.
  • When performing a large number of consecutive extraction processes in a template, it may take a lot of time to generate pages.
unit string 'px'

It is possible to specify the unit of the crop hint data of the return value.

  • 'px' OR '%'

Example

$crophint = crophints_get(array(
	'post_id' => 123
));

Return

(array) The crop hint data.

SUCCESS

Array
(
    [id] => 202  /* ID of Crop Hint */
    [post_id] => 123  /* Post ID of the source image */
    [status] => 'success'  /* Result status */
    [parent_width] => 2560  /* Width of the source image (always in 'px') */
    [parent_height] => 1707  /* Height of the source image (always in 'px') */
    [width] => 955  /* Width of Crop Hint */
    [height] => 1706  /* Height of Crop Hint */
    [vertices] => Array  /* Coordinates for each vertex of Crop Hint */
        (
            [0] => Array
                (
                    [x] => 1024
                    [y] => 0
                )

            [1] => Array
                (
                    [x] => 1979
                    [y] => 0
                )

            [2] => Array
                (
                    [x] => 1979
                    [y] => 1706
                )

            [3] => Array
                (
                    [x] => 1024
                    [y] => 1706
                )

        )

    [center] => Array  /* Central coordinates for Crop Hint */
        (
            [x] => 1501.5
            [y] => 853
		)

    [focus] => Array  /* Coordinates of the Focus set in Crop Hint. */
        (
            [x] => 1722
            [y] => 648
        )

    [load] => 'cache'  /* Data loading source */
    [type] => 'auto'  /* Type of Crop Hint */
    [unit] => 'px'  /* Unit of the data */
)
ERROR

Array
(
    [status] => 'error'
    [message] => (error message.)
)

1.2 crophints_get_hint_image (array $options)

Get the metadata of the Hint Image (= cropped image with the Crop Hint).

Crop Hint

Parameters

type default description
post_id * int null

Specifies the post ID of an image uploaded to the media library.

type string null

Specifies the type of the Crop Hint.

  • 'auto' OR 'manual'
  • If not specified, 'manual' will take precedence if the Manual Crop Hint exists, and then 'auto' will be selected.
force_generate boolean false

Specifies whether to immediately generate a Hint Image when it is not yet generated.

  • Because of the image generation process, it may take some time to generate the template page.
  • If a large number of images are generated continuously, the server may be overloaded.
  • If the Hint Image has already been generated, it will load faster.

Example

$hint_image = crophints_get_hint_image(array(
	'post_id' => $post_id
));

Return

(array) The metadata of Hint Image.

SUCCESS

Array
(
    [id] => 202  /* ID of Hint Image */
    [post_id] => 123  /* Post ID of the source image */
    [type] => 'auto'  /* Type of Crop Hint */
    [filepath] => 'htdocs/wp/wp-content/uploads/crophints/2020/04/image123_ch-auto.jpg'  /* Path of Hint Image */
    [url] => 'https://crophints.com/wp/wp-content/uploads/crophints/2020/04/image123_ch-auto.jpg'  /* URL of Hint Image */
    [width] => 955  /* Width of Hint Image */
    [height] => 1706  /* Height of Hint Image */
    [load] => 'cache'  /* Data loading source */
    [status] => 'success'  /* Result status */
)
ERROR

Array
(
    [status] => 'error'
    [message] => (error message.)
)

2 Smart Cropped Images

2.1 crophints_get_smartcrop (array $options)

Smart Cropped Images takes into account the Crop Hint extracted by the Cloud Vision AI and smartly crops the image to the maximum from the original image in any aspect ratio.

Retrieve the metadata of the crop area where the Smart Cropped Image is to be trimmed.

Crop Hint
Smart Crop

Parameters

type default description
post_id * int null

Specifies the post ID of an image uploaded to the media library.

type string null

Specifies the type of the Crop Hint.

  • 'auto' OR 'manual'
  • If not specified, 'manual' will take precedence if the Manual Crop Hint exists, and then 'auto' will be selected.
aspect float 1.0

Specify the aspect ratio.

unit string 'px'

It is possible to specify the unit of the crop hint data of the return value.

  • 'px' OR '%'

Example

$smartcrop = crophints_get_smartcrop(array(
	'post_id' => 245,
	'aspect' => .666
));

Return

(array) The metadata of hint image.

SUCCESS

Array
(
    [parent_width] => 2560  /* Width of the source image (always in 'px') */
    [parent_height] => 1707  /* Height of the source image (always in 'px') */
    [x] => 1250.12083636  /* X-coordinate of Smart Crop */
    [y] => 16  /* Y-coordinate of Smart Crop */
    [width] => 1126.206  /* Width of Smart Crop */
    [height] => 1691  /* Height of Smart Crop */
    [crophint] => 'manual'  /* Type of Crop Hint used as the source of Smart Crop calculation. */
    [unit] => 'px'  /* Unit of the data */
)

2.2 crophints_get_sci (array $options)

Reads the image metadata of the Smart Cropped Image culled from the image with the specified post_id.

If Smart Cropped Image is not generated, it returns the data corresponding to the wp_get_attachment_image_src() function runtime.

Crop Hint

Parameters

type default description
post_id * int null

Specifies the post ID of an image uploaded to the media library.

type string null

Specifies the type of the Crop Hint from which the Smart Cropped Image is generated.

  • 'auto' OR 'manual'
  • If not specified, 'manual' will take precedence if the Manual Crop Hint exists, and then 'auto' will be selected.
size string null

You can specify the size you want to get, which is the same as the size set in WordPress.

aspect float 1.0

Specifies the aspect ratio of the Smart Cropped Image.

force_generate boolean false

Specifies whether to generate the Smart Cropped Image immediately when there is no Smart Cropped Image of the specified condition.

  • The process of generating images generally tends to place a high load on the server.
  • We do not recommend an implementation that generates too many Smart Cropped Images at once in a template. Please use the auto-generated presets on the settings page to set the aspect ratio you often use.

Example

$smart_cropped_image = crophints_get_sci(array(
	'post_id' => 123,
	'size'    => 'w640',
	'aspect'  => .666
));

Return

(array) The metadata of Smart Cropped Image.

SUCCESS
// * 指定された条件の Smart Cropped Image が存在した場合

Array
(
    [status] => 'success'  /* Result status */
    [src] => Array  /* The image metadata */
        (
            [0] => 'https://crophints.com/wp/wp-content/crophints/uploads/2020/04/image123_ch-manual_sci-666_w640.jpg'
            [1] => 639
            [2] => 960
            [3] => 1
        )

    [size] => 'w640'  /* The size of the image */
    [aspect] => 0.666  /* Aspect ratio */
    [crophint] => 'manual'  /* Type of Crop Hint used as the source of Smart Crop calculation. */
    [is_sci] => 1  /* Whether the image metadata is Smart Cropped Image or not. */
    [load] => 'cache'  /* Data loading source */
)
SUCCESS_ERROR
// * 指定された条件の Smart Cropped Image が存在しなかった場合

Array
(
    [status] => 'success'  /* Result status */
    [src] => Array  /* The image metadata */
        (
            [0] => 'https://crophints.com/wp/wp-content/uploads/crophints/2020/04/image123-640x427.jpg'
            [1] => 640
            [2] => 427
            [3] => 1
        )

    [size] => 'w640'  /* The size of the image */
    [aspect] => 1.499  /* Aspect ratio */
    [is_sci] => 0  /* Whether the image metadata is Smart Cropped Image or not. */
)
ERROR

Array
(
    [status] => 'error'
    [message] => (error message.)
)