-
Notifications
You must be signed in to change notification settings - Fork 2
/
image-edit.php
37 lines (33 loc) · 1.22 KB
/
image-edit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<h1>Edit Image</h1>
<form action="/image-edit.php" method="post" enctype="multipart/form-data">
Select file to upload: <br>
<label for="image">Image</label>
<input type="file" name="image" id="image">
<br>
<label for="mask">Mask</label>
<input type="file" name="mask" id="mask">
<br>
<input type="submit" value="Upload File" name="submit">
</form>
<?php
require __DIR__ . '/vendor/autoload.php';
use Orhanerday\OpenAi\OpenAi;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (ob_get_contents()) ob_end_clean();
$open_ai_key = getenv('OPENAI_API_KEY');
$open_ai = new OpenAi($open_ai_key);
$tmp_file = $_FILES['image']['tmp_name'];
$file_name = basename($_FILES['image']['name']);
$image = curl_file_create($tmp_file, $_FILES['image']['type'], $file_name);
$tmp_file = $_FILES['mask']['tmp_name'];
$file_name = basename($_FILES['mask']['name']);
$mask = curl_file_create($tmp_file, $_FILES['mask']['type'], $file_name);
$result = $open_ai->imageEdit([
"image" => $image,
"mask" => $mask,
"prompt" => "A cute baby sea otter wearing a beret",
"n" => 2,
"size" => "256x256",
]);
echo $result;
}