צור צילומי מסך מושלמים של אתרים או המר HTML ישירות לתמונות על ידי שימוש בתכונות הבאות של ממשק ה- API של GrabzIt. עם זאת לפני שתתחיל לזכור את זה לאחר התקשרות אל URLToImage, HTMLToImage or FileToImage שיטות Save or SaveTo יש לקרוא לשיטה ליצירת התמונה.
נדרש פרמטר אחד בלבד על מנת לצלם צילום מסך של דף אינטרנט או להמיר HTML intתמונה כפי שמוצג בדוגמה הבאה.
$grabzIt->URLToImage("https://www.tesla.com"); //Then call the Save or SaveTo method
$grabzIt->HTMLToImage("<html><body><h1>Hello World!</h1></body></html>"); //Then call the Save or SaveTo method
$grabzIt->FileToImage("example.html"); //Then call the Save or SaveTo method
ה- PHP API של GrabzIt יכול ליצור תמונות בפורמטים רבים, כולל JPG, PNG, WEBP, BMP (ביט 8, 16, 24 או 32) ו- TIFF. פורמט ברירת המחדל לתמונות הוא JPG. עם זאת איכות התמונה של JPG עשויה להיות לא מספיק טובה עבור יישומים מסוימים בנסיבות אלה, פורמט PNG מומלץ לצילומי מסך של תמונות מכיוון שהוא נותן איזון טוב בין איכות לגודל הקובץ. הדוגמה הבאה מציגה תמונה שנוצרת באמצעות פורמט PNG.
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setFormat("png"); $grabzIt->URLToImage("https://www.tesla.com", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.png");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setFormat("png"); $grabzIt->HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.png");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setFormat("png"); $grabzIt->FileToImage("example.html", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.png");
גודל הדפדפן מתייחס לגודל חלון הדפדפן שישמש בעת צילום הצילום המסך ברוב המקרים, אין צורך להגדיר זאת מכיוון שגודל ברירת המחדל של הדפדפן יספיק לכל רוב המשימות. כדי לקבוע את גודל הדפדפן פשוט העבירו ערך ל- setBrowserWidth
ו setBrowserHeight
שיטות של GrabzItImageOptions מעמד.
קל לשנות את גודל התמונה, לעשות את זה בלי לעוות את התמונה זה קצת יותר קשה. כדי להפוך את כל התהליך לפשוט יותר אנו ממליצים להשתמש בזה מחשבון מימד תמונה פשוט.
אם ברצונך להגדיל את רוחב וגובה התמונה לגודל גדול יותר מרוחב וגובה הדפדפן, אשר כברירת מחדל הוא 1366 על ידי 728 פיקסלים, יש להגדיל את רוחב הגובה של הדפדפן כך שיתאים.
אתה יכול להעביר מזהה מותאם אישית אל ה- תמונה שיטות כמוצג להלן, ערך זה יוחזר למטפל PHP שלך ב- GrabzIt. לדוגמה, מזהה מותאם אישית זה יכול להיות מזהה בסיס נתונים, המאפשר לשייך צילום מסך או תמונה לרשומת מסד נתונים מסוימת.
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setCustomId(123456); $grabzIt->URLToImage("https://www.tesla.com", $options); //Then call the Save method $grabzIt->Save("http://www.example.com/handler.php");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setCustomId(123456); $grabzIt->HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", $options); //Then call the Save method $grabzIt->Save("http://www.example.com/handler.php");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setCustomId(123456); $grabzIt->FileToImage("example.html", $options); //Then call the Save method $grabzIt->Save("http://www.example.com/handler.php");
GrabzIt מאפשר לך לצלם צילום מסך מלא של דף אינטרנט שלם כדי לעשות זאת אתה צריך להעביר -1 ל setBrowserHeight
שיטה. כדי להבטיח שהתמונה תואמת את גודל הדפדפן, העבירו כ- 1 ל- setHeight
ו setWidth
שיטות.
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setBrowserHeight(-1); $options->setWidth(-1); $options->setHeight(-1); $grabzIt->URLToImage("https://www.tesla.com", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.jpg");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setBrowserHeight(-1); $options->setWidth(-1); $options->setHeight(-1); $grabzIt->HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.jpg");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setBrowserHeight(-1); $options->setWidth(-1); $options->setHeight(-1); $grabzIt->FileToImage("example.html", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.jpg");
אתה יכול גם להחזיר צילומי מסך שאינם קצוצים, אך היזהר שיכול ליצור תמונות גדולות. לשם כך העבירו -1 ל- setHeight
ו / או setWidth
שיטות. כל מימד שמועבר ל- -1 לא ייחתך.
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setWidth(-1); $options->setHeight(-1); $grabzIt->URLToImage("https://www.tesla.com", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.jpg");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setWidth(-1); $options->setHeight(-1); $grabzIt->HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.jpg");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setWidth(-1); $options->setHeight(-1); $grabzIt->FileToImage("example.html", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.jpg");
השימוש בערכים המיוחדים הללו פירושו שתוכלו ליצור צילום מסך המהווה גרסה בקנה מידה מלא של כל דף האינטרנט אם תרצו!
GrabzIt מאפשר לך לצלם צילום מסך של אלמנט HTML, כגון div
or span
לתייג ולתפוס את כל תוכנו. לשם כך יש לציין את אלמנט ה- HTML שברצונך למסך למסך בורר CSS.
... <div id="features"> <img src="http://www.example.com/peace.jpg"/><h3>World Peace Announced</h3> </div> ...
עבור הדוגמה למטה אנו נבחר את ה- div עם המזהה "features" ונציג אותו כתמונת JPEG 250 x 250px.
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); // The 250 parameters indicates that image should be sized to 250 x 250 px $options = new \GrabzIt\GrabzItImageOptions(); $options->setWidth(250); $options->setHeight(250); $options->setFormat("jpg"); $options->setTargetElement("#features"); $grabzIt->URLToImage("http://www.bbc.co.uk/news", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.jpg");
הדוגמה הבאה מצולמת צילום מסך נוסף של ה- div "תכונות" אך הפעם מוציא תמונת JPEG בגודל המדויק של ה- div.
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); // The -1 indicates that image should not be cropped $options = new \GrabzIt\GrabzItImageOptions(); $options->setWidth(-1); $options->setHeight(-1); $options->setBrowserHeight(-1); $options->setFormat("jpg"); $options->setTargetElement("#features"); $grabzIt->URLToImage("http://www.bbc.co.uk/news", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.jpg");