כלים ללכידה ולהמרה של האינטרנט

צלם תמונות מסך של אתר או המרת HTML לתמונות

ממשק API של רובי

הפק צילומי מסך טובים יותר של דפי אינטרנט או המר HTML ישירות לתמונות באמצעות התכונות הבאות של ממשק API רובי של GrabzIt. עם זאת לפני שתתחיל לזכור את זה לאחר התקשרות אל url_to_image, html_to_image or file_to_image שיטות save or save_to יש לקרוא לשיטה ליצירת התמונה.

אפשרויות בסיסיות

נדרש פרמטר אחד בלבד על מנת לצלם צילום מסך של דף אינטרנט או להמיר HTML intתמונה כפי שמוצג בדוגמה הבאה.

grabzItClient.url_to_image("https://www.tesla.com")
# Then call the save or save_to method
grabzItClient.html_to_image("<html><body><h1>Hello World!</h1></body></html>")
# Then call the save or save_to method
grabzItClient.file_to_image("example.html")
# Then call the save or save_to method

פורמטים של תמונות

ה- Ruby API של GrabzIt יכול לצלם צילומי מסך בכמה פורמטים, כולל JPG, PNG, WEBP, BMP (8 bit, 16 bit, 24 bit או 32 bit) ו- TIFF. פורמט ברירת המחדל של צילומי מסך של תמונות הוא JPG. עם זאת איכות התמונה של JPG עשויה להיות לא מספיק טובה עבור יישומים מסוימים בנסיבות אלה, פורמט PNG מומלץ לצילומי מסך של תמונות מכיוון שהוא נותן איזון טוב בין איכות לגודל קובץ. הדוגמה הבאה מציגה צילום מסך שצולם בפורמט PNG.

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::ImageOptions.new()
options.format = "png"

grabzItClient.url_to_image("https://www.tesla.com", options)
# Then call the save or save_to method
grabzItClient.save_to("result.png")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::ImageOptions.new()
options.format = "png"

grabzItClient.html_to_image("<html><body><h1>Hello World!</h1></body></html>", options)
# Then call the save or save_to method
grabzItClient.save_to("result.png")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::ImageOptions.new()
options.format = "png"

grabzItClient.file_to_image("example.html", options)
# Then call the save or save_to method
grabzItClient.save_to("result.png")

גודל הדפדפן

גודל הדפדפן מתייחס לגודל חלון הדפדפן שישמש בעת צילום הצילום המסך ברוב המקרים, אין צורך להגדיר זאת מכיוון שגודל ברירת המחדל של הדפדפן יספיק לכל רוב המשימות. כדי לקבוע את גודל הדפדפן פשוט העבירו ערך ל- browserWidth ו browserHeight שיטות של ImageOptions מעמד.

שנה את גודל התמונה

קל לשנות את גודל התמונה, לעשות את זה בלי לעוות את התמונה זה קצת יותר קשה. כדי להפוך את כל התהליך לפשוט יותר אנו ממליצים להשתמש בזה מחשבון מימד תמונה פשוט.

אם ברצונך להגדיל את רוחב וגובה התמונה לגודל גדול יותר מרוחב וגובה הדפדפן, אשר כברירת מחדל הוא 1366 על ידי 728 פיקסלים, יש להגדיל את רוחב הגובה של הדפדפן כך שיתאים.

מזהה מותאם אישית

אתה יכול להעביר מזהה מותאם אישית אל ה- תמונה שיטות כמוצג להלן, ערך זה מוחזר לאחר מכן למטפל GrabzIt Ruby שלך. לדוגמה, מזהה מותאם אישית זה יכול להיות מזהה בסיס נתונים, המאפשר לשייך צילום מסך לרשומת מסד נתונים מסוימת.

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::ImageOptions.new()
options.customId = "123456"

grabzItClient.url_to_image("https://www.tesla.com", options)
# Then call the save method
grabzItClient.save("http://www.example.com/handler/index")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::ImageOptions.new()
options.customId = "123456"

grabzItClient.html_to_image("<html><body><h1>Hello World!</h1></body></html>", options)
# Then call the save method
grabzItClient.save("http://www.example.com/handler/index")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::ImageOptions.new()
options.customId = "123456"

grabzItClient.file_to_image("example.html", options)
# Then call the save method
grabzItClient.save("http://www.example.com/handler/index")

צילום מסך באורך מלא

GrabzIt מאפשר לך לצלם צילום מסך מלא של דף אינטרנט שלם כדי לעשות זאת אתה צריך להעביר -1 ל browserHeight שיטה. כדי להבטיח שהתמונה תואמת את גודל הדפדפן, העבירו כ- 1 ל- height ו width תכונות.

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::ImageOptions.new()
options.browserHeight = -1
options.width = -1
options.height = -1

grabzItClient.url_to_image("https://www.tesla.com", options)
# Then call the save or save_to method
grabzItClient.save_to("result.jpg")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::ImageOptions.new()
options.browserHeight = -1
options.width = -1
options.height = -1

grabzItClient.html_to_image("<html><body><h1>Hello World!</h1></body></html>", options)
# Then call the save or save_to method
grabzItClient.save_to("result.jpg")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::ImageOptions.new()
options.browserHeight = -1
options.width = -1
options.height = -1

grabzItClient.file_to_image("example.html", options)
# Then call the save or save_to method
grabzItClient.save_to("result.jpg")

אתה יכול גם להחזיר תמונות ממוזערות שאינן קצוצות, אך היזהר מכיוון שיכול ליצור תמונות גדולות. לשם כך העבירו -1 ל- height ו / או width שיטות. הממד שמועבר -1 לא ייחתך.

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::ImageOptions.new()
options.width = -1
options.height = -1

grabzItClient.url_to_image("https://www.tesla.com", options)
# Then call the save or save_to method
grabzItClient.save_to("result.jpg")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::ImageOptions.new()
options.width = -1
options.height = -1

grabzItClient.html_to_image("<html><body><h1>Hello World!</h1></body></html>", options)
# Then call the save or save_to method
grabzItClient.save_to("result.jpg")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

options = GrabzIt::ImageOptions.new()
options.width = -1
options.height = -1

grabzItClient.file_to_image("example.html", options)
# Then call the save or save_to method
grabzItClient.save_to("result.jpg")
שים לב שאין רוחב דפדפן באורך מלא!

השימוש בערכים המיוחדים הללו פירושו שתוכלו ליצור צילום מסך המהווה גרסה בקנה מידה מלא של כל דף האינטרנט אם תרצו!

צלם תמונת מסך של אלמנט עמוד

GrabzIt מאפשר לך לצלם צילום מסך של אלמנט HTML, כגון div or span לתייג ולתפוס את כל תוכנו. לשם כך יש לציין את אלמנט ה- HTML שברצונך למסך למסך בורר CSS.

...
<div id="features">
	<img src="http://www.example.com/rocket.jpg"/><h3>Rocket Launch Next Week</h3>
</div>
...

עבור הדוגמה למטה אנו נבחר את ה- div עם המזהה "features" ונציג אותו כתמונת JPEG 250 x 250px.

grabzItClient = GrabzIt::Client.new("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 = GrabzIt::ImageOptions.new()
options.width = 250
options.height = 250
options.format = "jpg"
options.targetElement = "#features"

grabzItClient.url_to_image("http://www.bbc.co.uk/news", options)
# Then call the save or save_to method
grabzItClient.save_to("result.jpg")

הדוגמה הבאה מצולמת צילום מסך נוסף של ה- div "תכונות" אך הפעם מוציא תמונת JPEG בגודל המדויק של ה- div.

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")

# The -1 indicates that image should not be cropped
options = GrabzIt::ImageOptions.new()
options.width = 250
options.height = 250
options.format = "jpg"
options.targetElement = "#features"
options.browserHeight = -1

grabzItClient.url_to_image("http://www.bbc.co.uk/news", options)
# Then call the save or save_to method
grabzItClient.save_to("result.jpg")