<?php
//header('Content-Type: application/json');
function translateText($text, $targetLanguage) {
$url = 'https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=' . $targetLanguage . '&dt=t&ie=UTF-8&oe=UTF-8&otf=1&ssel=0&tsel=0&kc=7&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&q=' . urlencode($text);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$json = json_decode($response, true);
return isset($json[0][0][0]) ? $json[0][0][0] : $text; // ارجع النص الأصلي إذا لم يكن الترجمة موجودة
}
function containsArabic($string) {
return preg_match('/\p{Arabic}/u', $string) > 0;
}
if (isset($_GET['text'])) {
$T = $_GET['text'];
// تحقق من وجود حروف عربية
if (containsArabic($T)) {
$text_t = translateText($T, "en");
} else {
$text_t = $T;
}
// إعداد الطلب إلى API الخارجي
$url = 'https://api.getimg.ai/v1/stable-diffusion-xl/text-to-image';
$headers = [
'Host: api.getimg.ai',
'Accept: application/json',
'Authorization: Bearer key-3XbWkFO34FVCQUnJQ6A3qr702Eu7DDR1dqoJOyhMHqhruEhs22KUzR7w631ZFiA5OFZIba7i44qDQEMpKxzegOUm83vCfILb',
'Content-Type: application/json',
'User-Agent: okhttp/4.12.0',
'Connection: keep-alive',
];
$data = json_encode([
'height' => 1024,
'model' => 'realvis-xl-v4',
'negative_prompt' => 'nude, naked, porn, sexual, explicit, adult, sex, xxx, erotic, blowjob, masturbation, intercourse, hentai, vulgar, profane, obscene, dirty, slut, whore, rape, fetish, gangbang, threesome, stripper, escort,',
'prompt' => $text_t, // استخدم النص المترجم أو الأصلي
'response_format' => 'url',
'seed' => 0,
'steps' => 30,
'width' => 1024,
]);
// تنفيذ طلب cURL
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo json_encode(['error' => 'حدث خطأ في الاتصال: ' . curl_error($ch)]);
curl_close($ch);
exit;
}
curl_close($ch);
$res = json_decode($response, true);
// تحقق من وجود URL في الاستجابة
if (isset($res['url']) && $res['url']) {
echo json_encode(['url' => $res['url']]);
} else {
echo json_encode(['error' => 'حدث خطأ في معالجة طلبك.']);
}
} else {
echo json_encode(['error' => 'يرجى تقديم نص عبر GET.']);
}
?>
API Pictures with use AI
@MROAN8
@PHP88