image-helper-wordpress/README.md

38 lines
2.1 KiB
Markdown
Raw Permalink Normal View History

2024-11-18 23:00:44 +01:00
# Description
I wanted to write a tool in Rust which takes an Image as command line argument and then sends this image to ChatGPT to generate an image description. Once it has received the image description it uploads the image to a WordPress media library as new image. After the upload it will add the image description received via ChatGPT as the ALT text and description of the uploaded image in the WordPress media library.
The script will take the URL of the Wordpress site, the username and application password for Wordpress as well as the OpenAPI URL, ChatGPT model and OpenAPI API key as configuration parameters from a `.env` file.
# Prerequisites
To use this application you need an account for ChatGPT and generate an access token so you can use the OpenAI API. Instructions can be found at [their documentation site](https://platform.openai.com/docs/quickstart)
In addition, you should have a WordPress installation with a recent version of WordPress and an application token configured for your user account. This allows programmatic access to your wordpress instance. This can be found under Users -> Profile -> Application Passwords
2024-11-18 23:00:44 +01:00
# preparation
Install Rust on your machine. Copy the `.env.example` to `.env`
The `.env` file is either expected in the current working directory OR in `$HOME/.image-helper-wordpress/.env`
2024-11-18 23:16:34 +01:00
# testing
2024-11-18 23:00:44 +01:00
`cargo run -- /path/to/your/image.jpg`
# compilation
`cargo build --release`
will build the binary in `./target/release/image-helper-wordpress`
2024-11-18 23:16:34 +01:00
# running
```
$image-helper-wordpress: ./target/release/image-helper-wordpress /Users/username/Pictures/DJI_0247.jpg
Generated description: Aerial view of a circular lake surrounded by dense forest, with a small cluster of houses lining one edge. A second smaller lake is visible in the background, also encircled by forest.
Successfully uploaded image to WordPress with description
Image URL: https://example.wordpress.com/wp-content/uploads/2024/11/DJI_0247-scaled.jpg
```
[![asciicast](https://asciinema.mxhdr.net/a/8DVzLQbUuQcAZc897Iz5kR4b5.svg)](https://asciinema.mxhdr.net/a/8DVzLQbUuQcAZc897Iz5kR4b5)