Hey!
Is it possible to add “style filters”, so the users can generate only a set style of images?
Maybe customize prompts?
I would like to know how to limit by user (not connected but via their IP or other if you have ideas) the number of generations they are entitled to, so hide the form once it has been exceeded.
]]>Bonjour, j’ai acheté le plugin Artiste Image Generator Pro.
Problème : l’édition d’image ne fonctionne pas. J’upload l’image, je la recadre, j’ajoute un masque et un prompt. La génération semble fonctionner mais affiche 3 fois l’image d’origine sans aucune modification. Auriez-vous une idée de l’origine du problème ? Merci d’avance pour votre réponse
This code will not store images into WordPress Media Library. Feel free to adapt the code to your needs. Original request by @CarloLupo.
Replace the content of add_to_media() function in admin/class-artist-image-generator-admin.php l.600 by this one and customize $upload_dir var :
public function add_to_media(): mixed
{
require_once ABSPATH . "/wp-admin/includes/image.php";
require_once ABSPATH . "/wp-admin/includes/file.php";
require_once ABSPATH . "/wp-admin/includes/media.php";
$url = sanitize_url($_POST['url']);
$alt = sanitize_text_field($_POST['description']);
// Download url to a temp file
$tmp = download_url($url);
if (is_wp_error($tmp)) {
return false;
}
// Get the filename and extension ("photo.png" => "photo", "png")
$filename = pathinfo($url, PATHINFO_FILENAME);
$extension = pathinfo($url, PATHINFO_EXTENSION);
// An extension is required or else WordPress will reject the upload
if (!$extension) {
// Look up mime type, example: "/photo.png" -> "image/png"
$mime = mime_content_type($tmp);
$mime = is_string($mime) ? sanitize_mime_type($mime) : false;
// Only allow certain mime types because mime types do not always end in a valid extension (see the .doc example below)
$mime_extensions = array(
'image/jpg' => 'jpg',
'image/jpeg' => 'jpeg',
'image/gif' => 'gif',
'image/png' => 'png'
);
$extension = $mime_extensions[$mime] ?? false;
if (!$extension) {
// Could not identify extension
@unlink($tmp);
return false;
}
}
// Define the path of the third-party folder where you want to save files
$upload_dir = ABSPATH . 'custom_images/'; // REPLACE BY YOUR PATH HERE
// Maybe you should add uniqid() to avoid same filenames in the directory
$file_name = sanitize_title($alt, $filename) . /*'_' . uniqid() .*/ ".$extension";
$target_file = $upload_dir . $file_name;
if (!rename($tmp, $target_file)) {
wp_send_json_error('Error renaming file');
}
@unlink($tmp);
// Success, return attachment ID (int). In this code, will return 0 anyway
wp_send_json_success(['attachment_id' => 0]);
if (defined('DOING_AJAX') && DOING_AJAX) {
wp_die();
}
}
]]>