File size: 5,095 Bytes
9d8dcd2 93c860e 9d8dcd2 93c860e 9d8dcd2 93c860e 9d8dcd2 93c860e 9d8dcd2 93c860e 9d8dcd2 93c860e 9d8dcd2 93c860e 9d8dcd2 93c860e 9d8dcd2 93c860e ae0d5eb 9d8dcd2 93c860e 9d8dcd2 93c860e 9d8dcd2 93c860e 9d8dcd2 93c860e 9d8dcd2 |
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
let selectedHashtag = "#StandWithPalestine"; // الهاشتاج الافتراضي
function updateHashtag() {
selectedHashtag = document.getElementById('hashtag-select').value;
document.getElementById('hashtag1').textContent = selectedHashtag;
document.getElementById('hashtag2').textContent = selectedHashtag;
}
async function loadTwitterImage() {
const username = document.getElementById('username-input').value.trim();
if (!username) {
alert("الرجاء إدخال اسم مستخدم تويتر.");
return;
}
const loading = document.getElementById('loading');
const successMessage = document.getElementById('success-message');
loading.style.display = 'block';
successMessage.style.display = 'none';
try {
const img1 = document.getElementById('profile-image1');
const img2 = document.getElementById('profile-image2');
const imageUrl = `https://unavatar.io/x/${username}`;
img1.crossOrigin = 'anonymous';
img2.crossOrigin = 'anonymous';
img1.src = `${imageUrl}?t=${new Date().getTime()}`;
img2.src = `${imageUrl}?t=${new Date().getTime()}`;
img1.onload = img2.onload = () => {
loading.style.display = 'none';
successMessage.style.display = 'block';
console.log("تم تحميل الصورة بنجاح");
};
img1.onerror = img2.onerror = () => {
loading.style.display = 'none';
alert("حدث خطأ أثناء تحميل الصورة.");
};
} catch (error) {
loading.style.display = 'none';
console.error("خطأ:", error);
alert("حدث خطأ أثناء تحميل الصورة. الرجاء التحقق من اسم المستخدم.");
}
}
function handleImageUpload(event) {
const file = event.target.files[0];
if (file) {
if (!file.type.startsWith('image/')) {
alert("الرجاء اختيار ملف صورة صالح.");
return;
}
const loading = document.getElementById('loading');
const successMessage = document.getElementById('success-message');
loading.style.display = 'block';
successMessage.style.display = 'none';
const reader = new FileReader();
reader.onload = function(e) {
const img1 = document.getElementById('profile-image1');
const img2 = document.getElementById('profile-image2');
img1.src = e.target.result;
img2.src = e.target.result;
img1.onload = img2.onload = () => {
loading.style.display = 'none';
successMessage.style.display = 'block';
console.log("تم تحميل الصورة بنجاح");
};
img1.onerror = img2.onerror = () => {
loading.style.display = 'none';
alert("حدث خطأ أثناء تحميل الصورة.");
};
};
reader.readAsDataURL(file);
}
}
function downloadImage(type) {
const profileImg = document.getElementById(type === 'transparent' ? 'profile-image1' : 'profile-image2');
const overlayImg = document.getElementById(type === 'transparent' ? 'overlay-image1' : 'overlay-image2');
if (!profileImg.src || profileImg.src === window.location.href) {
alert("الرجاء تحميل صورة أولاً.");
return;
}
try {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = 300;
canvas.height = 300;
// رسم صورة ps.png
ctx.drawImage(overlayImg, 0, 0, canvas.width, canvas.height);
// تفعيل الشفافية إذا كانت الصورة الشفافة
if (type === 'transparent') {
ctx.globalAlpha = 0.5;
}
// رسم الصورة المستوردة
if (type === 'circle') {
ctx.beginPath();
ctx.arc(canvas.width / 2, canvas.height / 2, canvas.width / 2 * 0.8, 0, Math.PI * 2);
ctx.closePath();
ctx.clip();
ctx.drawImage(profileImg, canvas.width * 0.1, canvas.height * 0.1, canvas.width * 0.8, canvas.height * 0.8);
} else {
ctx.drawImage(profileImg, 0, 0, canvas.width, canvas.height);
}
ctx.globalAlpha = 1;
// إضافة الهاشتاج
ctx.font = "16px Arial";
ctx.fillStyle = "white";
ctx.textAlign = "center";
ctx.fillText(selectedHashtag, canvas.width / 2, canvas.height - 15);
// تصدير الصورة
const link = document.createElement('a');
link.download = type === 'transparent' ? 'transparent-image.png' : 'circle-image.png';
link.href = canvas.toDataURL('image/png');
link.click();
} catch (error) {
console.error("خطأ أثناء التصدير:", error);
alert("حدث خطأ أثناء تصدير الصورة. الرجاء المحاولة مرة أخرى.");
}
} |