أدوات لالتقاط وتحويل الويب

التقاط لقطات من موقع الويب أو تحويل HTML إلى صور

API روبي

يمكنك إنتاج لقطات شاشة أفضل لصفحات الويب أو تحويل HTML مباشرة إلى صور باستخدام الميزات التالية في GrabzIt's Ruby API. ولكن قبل أن تبدأ تذكر أنه بعد استدعاء 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

صورة تنسيقات

يمكن لـ GrabzIt's Ruby API التقاط لقطات شاشة للصور بتنسيقات متعددة ، بما في ذلك 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 بمعرف "الميزات" ونخرجه كصورة XEGN 250px JPEG.

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")

المثال التالي يأخذ لقطة شاشة أخرى لـ "features" 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")