Python: requests doesn't get the whole content of a URL - python-3.x

Here is the URL that I am looking at:
url = https://i.instagram.com/api/v1/users/8538441802/info/
If I copy this url on the navigation bar of a web-browser I see this content:
{"user": {"pk": 8538441802, "username": "bobby_ww4", "full_name": "\ud83c\udf78 B O B B Y \ud83c\udf78", "is_private": false, "profile_pic_url": "https://scontent-sjc3-1.cdninstagram.com/vp/8a743eb7285d9cec268248e7fe6b018e/5D0470C8/t51.2885-19/s150x150/50103965_250281542552654_8842589758333911040_n.jpg?_nc_ht=scontent-sjc3-1.cdninstagram.com", "profile_pic_id": "1963771869542832625_8538441802", "is_verified": false, "has_anonymous_profile_picture": false, "media_count": 42, "follower_count": 2132, "following_count": 2881, "following_tag_count": 0, "biography": "Cake murder 9may\nLUNATIC \ud83d\udc40\nFashionholic \ud83d\udc54\n Attrangi \nUncontrolled rage \ud83d\ude44\nKDM LOVER \u2620\nHold the sea in my embrance", "external_url": "", "total_igtv_videos": 0, "total_ar_effects": 0, "reel_auto_archive": "on", "usertags_count": 44, "is_favorite": false, "is_interest_account": false, "hd_profile_pic_versions": [{"width": 320, "height": 320, "url": "https://scontent-sjc3-1.cdninstagram.com/vp/e6dc6596c0fed678fe6e520e020a1cbc/5D1C6238/t51.2885-19/s320x320/50103965_250281542552654_8842589758333911040_n.jpg?_nc_ht=scontent-sjc3-1.cdninstagram.com"}, {"width": 640, "height": 640, "url": "https://scontent-sjc3-1.cdninstagram.com/vp/4dd3319b1972445ce27eed7c827afbc4/5D033F57/t51.2885-19/s640x640/50103965_250281542552654_8842589758333911040_n.jpg?_nc_ht=scontent-sjc3-1.cdninstagram.com"}], "hd_profile_pic_url_info": {"url": "https://scontent-sjc3-1.cdninstagram.com/vp/30ff98f96900aee2a5604b7d833e0e85/5D130A32/t51.2885-19/50103965_250281542552654_8842589758333911040_n.jpg?_nc_ht=scontent-sjc3-1.cdninstagram.com", "width": 1080, "height": 1080}, "mutual_followers_count": 0, "has_highlight_reels": true, "can_be_reported_as_fraud": false, "direct_messaging": "UNKNOWN", "fb_page_call_to_action_id": "", "address_street": "", "business_contact_method": "CALL", "category": "Fashion Model", "city_id": 106313309406070, "city_name": "Ludhiana, Punjab, India", "contact_phone_number": "+919914934996", "is_call_to_action_enabled": false, "latitude": 30.9, "longitude": 75.85, "public_email": "bobbyvaid1137#gmail.com", "public_phone_country_code": "91", "public_phone_number": "9914934996", "zip": "", "instagram_location_id": "", "is_business": true, "account_type": 2, "can_hide_category": false, "can_hide_public_contacts": false, "should_show_category": true, "should_show_public_contacts": true, "include_direct_blacklist_status": true, "is_potential_business": false, "is_bestie": false, "has_unseen_besties_media": false, "show_account_transparency_details": false, "auto_expand_chaining": false, "highlight_reshare_disabled": false}, "status": "ok"}
NOTE: you must be logged in Instagram to see the above content.
Here is the line that I use requests to read this page:
page = requests.get(url, headers={"User-Agent": "Mozilla"})
If I look at the page.text this is what I see:
{"user": {"pk": 8538441802, "username": "bobby_ww4", "full_name": "\ud83c\udf78 B O B B Y \ud83c\udf78", "is_private": false, "profile_pic_url": "https://scontent-sjc3-1.cdninstagram.com/vp/8a743eb7285d9cec268248e7fe6b018e/5D0470C8/t51.2885-19/s150x150/50103965_250281542552654_8842589758333911040_n.jpg?_nc_ht=scontent-sjc3-1.cdninstagram.com", "profile_pic_id": "1963771869542832625_8538441802", "is_verified": false, "has_anonymous_profile_picture": false, "media_count": 42, "follower_count": 2132, "following_count": 2881, "following_tag_count": 0, "biography": "Cake murder 9may\nLUNATIC \ud83d\udc40\nFashionholic \ud83d\udc54\n Attrangi \nUncontrolled rage \ud83d\ude44\nKDM LOVER \u2620\nHold the sea in my embrance", "external_url": "", "total_igtv_videos": 0, "total_ar_effects": 0, "reel_auto_archive": "on", "usertags_count": 44, "is_interest_account": false, "hd_profile_pic_versions": [{"width": 320, "height": 320, "url": "https://scontent-sjc3-1.cdninstagram.com/vp/e6dc6596c0fed678fe6e520e020a1cbc/5D1C6238/t51.2885-19/s320x320/50103965_250281542552654_8842589758333911040_n.jpg?_nc_ht=scontent-sjc3-1.cdninstagram.com"}, {"width": 640, "height": 640, "url": "https://scontent-sjc3-1.cdninstagram.com/vp/4dd3319b1972445ce27eed7c827afbc4/5D033F57/t51.2885-19/s640x640/50103965_250281542552654_8842589758333911040_n.jpg?_nc_ht=scontent-sjc3-1.cdninstagram.com"}], "hd_profile_pic_url_info": {"url": "https://scontent-sjc3-1.cdninstagram.com/vp/30ff98f96900aee2a5604b7d833e0e85/5D130A32/t51.2885-19/50103965_250281542552654_8842589758333911040_n.jpg?_nc_ht=scontent-sjc3-1.cdninstagram.com", "width": 1080, "height": 1080}, "has_highlight_reels": true, "can_be_reported_as_fraud": false, "is_potential_business": false, "auto_expand_chaining": false, "highlight_reshare_disabled": false}, "status": "ok"}
As it can be seen on the web-browser we can see some information, like contact_phone_number that cannot be seen in the page.txt.
Why is that and how can I use requests or any othr Python functions to read exactly what I can see on a web-browser?

Related

Pimcore: New product class not visible in e-commerce product list

Goal
Data objects of my data object class Product should be visible in the e-commerce Pimcore site.
Current Setup
Current Demo and Blue Print Application for Pimcore
I create a new data object class called Product. Parent PHP class is set to \App\Model\Product\AbstractProduct (Complete class definition export attached)
Created a new data object based on the Product class.
Result
The new product is not visible in the shop. There is no error shown up either.
What I also tried
Based on the Index Service documentation I manually updated the index, without any effect.
$ php bin/console ecommerce:indexservice:bootstrap --update-index
Processing 1 Product in segments of 50, batches of 50, 1 round, 1 batch in 1 process
1/1 [============================] 100% < 1 sec/< 1 sec 48.5 MiB
Processed 1 Product.
Attached complete class definition export
{
"id": "PROD",
"description": "",
"modificationDate": 1669880184,
"parentClass": "\\App\\Model\\Product\\AbstractProduct",
"implementsInterfaces": "",
"listingParentClass": "",
"useTraits": "",
"listingUseTraits": "",
"allowInherit": true,
"allowVariants": true,
"showVariants": true,
"layoutDefinitions": {
"name": "pimcore_root",
"type": null,
"region": null,
"title": null,
"width": 0,
"height": 0,
"collapsible": false,
"collapsed": false,
"bodyStyle": null,
"datatype": "layout",
"permissions": null,
"children": [
{
"name": "Layout",
"type": null,
"region": null,
"title": "",
"width": "",
"height": "",
"collapsible": false,
"collapsed": false,
"bodyStyle": "",
"datatype": "layout",
"permissions": null,
"children": [
{
"name": "Base Data",
"type": null,
"region": null,
"title": "Base Data",
"width": "",
"height": "",
"collapsible": false,
"collapsed": false,
"bodyStyle": "",
"datatype": "layout",
"permissions": null,
"children": [
{
"name": "productName",
"title": "Product Name",
"tooltip": "",
"mandatory": true,
"noteditable": false,
"index": true,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"fieldtype": "input",
"relationType": false,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false,
"width": "",
"defaultValue": null,
"columnLength": 190,
"regex": "",
"regexFlags": [],
"unique": true,
"showCharCount": false,
"defaultValueGenerator": ""
},
{
"name": "localizedfields",
"title": "",
"tooltip": "",
"mandatory": false,
"noteditable": false,
"index": null,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"fieldtype": "localizedfields",
"relationType": false,
"invisible": false,
"visibleGridView": true,
"visibleSearch": true,
"children": [
{
"name": "description",
"title": "Description",
"tooltip": "",
"mandatory": false,
"noteditable": false,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"fieldtype": "textarea",
"relationType": false,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false,
"width": "",
"height": "",
"maxLength": null,
"showCharCount": false,
"excludeFromSearchIndex": false
},
{
"name": "packaging",
"title": "Packaging",
"tooltip": "",
"mandatory": false,
"noteditable": false,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"fieldtype": "input",
"relationType": false,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false,
"width": "",
"defaultValue": null,
"columnLength": 190,
"regex": "",
"regexFlags": [],
"unique": false,
"showCharCount": false,
"defaultValueGenerator": ""
}
],
"region": null,
"layout": null,
"width": "",
"height": "",
"maxTabs": null,
"border": false,
"provideSplitView": false,
"tabPosition": null,
"hideLabelsWhenTabsReached": null,
"fieldDefinitionsCache": null,
"permissionView": null,
"permissionEdit": null,
"labelWidth": 0,
"labelAlign": "left"
},
{
"name": "image",
"title": "Image",
"tooltip": "",
"mandatory": false,
"noteditable": false,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"fieldtype": "image",
"relationType": false,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false,
"width": "",
"height": "",
"uploadPath": ""
},
{
"name": "group",
"title": "Group",
"tooltip": "",
"mandatory": false,
"noteditable": false,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"fieldtype": "manyToOneRelation",
"relationType": true,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false,
"classes": [
{
"classes": "ProductGroup"
}
],
"pathFormatterClass": "",
"width": "",
"assetUploadPath": "",
"objectsAllowed": true,
"assetsAllowed": false,
"assetTypes": [],
"documentsAllowed": false,
"documentTypes": []
},
{
"name": "categories",
"title": "Categories",
"tooltip": "",
"mandatory": false,
"noteditable": false,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"fieldtype": "manyToManyObjectRelation",
"relationType": true,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false,
"classes": [
{
"classes": "Category"
}
],
"pathFormatterClass": "",
"width": "",
"height": "",
"maxItems": null,
"visibleFields": "id,fullpath,name",
"allowToCreateNewObject": false,
"optimizedAdminLoading": false,
"enableTextSelection": false,
"visibleFieldDefinitions": []
}
],
"locked": false,
"fieldtype": "panel",
"layout": null,
"border": false,
"icon": "",
"labelWidth": 0,
"labelAlign": "left"
},
{
"name": "Attributes",
"type": null,
"region": null,
"title": "Attributes",
"width": "",
"height": "",
"collapsible": false,
"collapsed": false,
"bodyStyle": "",
"datatype": "layout",
"permissions": null,
"children": [
{
"name": "attributes",
"title": "Attributes",
"tooltip": "",
"mandatory": false,
"noteditable": false,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"fieldtype": "objectbricks",
"relationType": false,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false,
"allowedTypes": [
"EdgebandingAttributes"
],
"maxItems": null,
"border": false
},
{
"name": "saleInformation",
"title": "Sale Information",
"tooltip": "",
"mandatory": false,
"noteditable": false,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"fieldtype": "objectbricks",
"relationType": false,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false,
"allowedTypes": [
"SaleInformation"
],
"maxItems": null,
"border": false
}
],
"locked": false,
"fieldtype": "panel",
"layout": null,
"border": false,
"icon": "",
"labelWidth": 0,
"labelAlign": "left"
}
],
"locked": false,
"fieldtype": "tabpanel",
"border": false,
"tabPosition": null
}
],
"locked": false,
"fieldtype": "panel",
"layout": null,
"border": false,
"icon": null,
"labelWidth": 100,
"labelAlign": "left"
},
"icon": "",
"previewUrl": "",
"group": "Product Data",
"showAppLoggerTab": false,
"linkGeneratorReference": "",
"previewGeneratorReference": "",
"compositeIndices": [],
"generateTypeDeclarations": true,
"showFieldLookup": false,
"propertyVisibility": {
"grid": {
"id": true,
"key": false,
"path": true,
"published": true,
"modificationDate": true,
"creationDate": true
},
"search": {
"id": true,
"key": false,
"path": true,
"published": true,
"modificationDate": true,
"creationDate": true
}
},
"enableGridLocking": false
}
I finally got it to work (after my last answer which was supposed to be a comment, my bad :D )
did you check the following:
1 Class override
https://pimcore.com/docs/pimcore/current/Development_Documentation/Extending_Pimcore/Overriding_Models.html
in /config/ecommerce/base-ecommerce.yaml
pimcore:
models:
class_overrides:
Pimcore\Model\DataObject\YourClass: App\Model\Product\YourClass
make sure you clear the cache like in the documentation
./bin/console cache:clear --no-warmup && ./bin/console pimcore:cache:clear
2 Check all Car Class names in Model / Controller
For example:
src/controller/productController.php
src/Model/Adminstyle/Car --> to your Class
src/Model/Car --> to your Class
3 Make sure that saving a product of yours gets in the index
I saw that on saving the object in the backend, i got a log that the object was not indexed.
https://pimcore.com/docs/pimcore/current/Development_Documentation/E-Commerce_Framework/Index_Service/Product_Index_Configuration/Data_Architecture_and_Indexing_Process.html
I had some other issues which where 100% not meant to be fixed like i did. So try how far you come with this
edit: typo

Creating a website-popup in Node-RED Dashboard

I'm creating an Interactive Floor Plan using Node-RED (with Dashboard and "node-red-contrib-ui-svg"
My problem: I want a Website-popup in the Node-RED Dashboard by clicking on an information icon but i don't know how to create the popup. I tryed it with the "http in", "http request", "http response" and function nodes, but it didn't work. Maybe i just don't get the payload right?
By clicking on the SVG, a event is starting and the SVG Node sends a payload to the output.
Later there should be multiple events with different SVGs opening different URL-popups
Does someone know, if it is possible to create a popup in the Node-RED Dashboard and if yes, tell me how i can do it?
Here is a small example flow of what i tried:
[
{
"id": "213370b.a1a7e9",
"type": "tab",
"label": "Floorplan",
"disabled": false,
"info": ""
},
{
"id": "3a8acfc1.2d033",
"type": "debug",
"z": "213370b.a1a7e9",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 570,
"y": 100,
"wires": []
},
{
"id": "3d085e29.713452",
"type": "http in",
"z": "213370b.a1a7e9",
"name": "googl",
"url": "svg",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 90,
"y": 100,
"wires": [
[
"3e9f0610.1b40da"
]
]
},
{
"id": "7e8c6b26.c6b194",
"type": "http response",
"z": "213370b.a1a7e9",
"name": "",
"statusCode": "",
"headers": {},
"x": 570,
"y": 60,
"wires": []
},
{
"id": "e6a43abb.2208c8",
"type": "function",
"z": "213370b.a1a7e9",
"name": "",
"func": "msg.responseUrl=msg.payload;\nmsg.payload=msg.payload\n\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 450,
"y": 80,
"wires": [
[
"7e8c6b26.c6b194",
"3a8acfc1.2d033"
]
]
},
{
"id": "3e9f0610.1b40da",
"type": "http request",
"z": "213370b.a1a7e9",
"name": "",
"method": "GET",
"ret": "txt",
"paytoqs": false,
"url": "nodered.org",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 270,
"y": 100,
"wires": [
[
"e6a43abb.2208c8"
]
]
},
{
"id": "2360d5fd.e4dc9a",
"type": "ui_svg_graphics",
"z": "213370b.a1a7e9",
"group": "ff128f4a.e252",
"order": 1,
"width": 0,
"height": 0,
"svgString": "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0\" y=\"0\" height=\"100\" viewBox=\"0 0 100 100\" width=\"100\"><rect id=\"svgEditorBackground\" x=\"0\" y=\"0\" width=\"100\" height=\"100\" style=\"fill:none; stroke: none;\"/><defs id=\"svgEditorDefs\"><symbol id=\"2139\" viewBox=\"0 0 64 64\" preserveAspectRatio=\"xMidYMid meet\"><rect x=\"0\" y=\"0\" width=\"64\" height=\"64\" style=\"stroke:none;fill:none;\"/><g xmlns=\"http://www.w3.org/2000/svg\"><circle cx=\"32\" cy=\"32\" fill=\"#42ade2\" r=\"30\"/><g fill=\"#fff\"><path d=\"m36.51 25h-6.992c-2.633 0-5.145 1.05-5.584 2.333-.436 1.284.447 2.334 1.965 2.334s2.072 2.02 1.23 4.492l-4.889 14.349c-.844 2.471.619 4.492 3.252 4.492h6.992c2.633 0 5.143-1.051 5.582-2.333.436-1.283-.447-2.335-1.963-2.335-1.518 0-2.072-2.02-1.23-4.491l4.889-14.349c.843-2.47-.619-4.492-3.252-4.492\"/><path d=\"m36.29 11c-2.666 0-5.406 2.238-6.121 5-.717 2.761.869 4.999 3.533 4.999 2.668 0 5.408-2.238 6.123-4.999.717-2.763-.867-5-3.535-5\"/></g></g></symbol><polygon id=\"svgEditorIconDefs\" style=\"fill:rosybrown;\"/></defs><use xlink:href=\"#2139\" x=\"4.410\" y=\"4.552\" width=\"19.061\" height=\"19.061\" id=\"svg_i\" transform=\"matrix(1.87014 0 0 1.87014 -2.59955 -2.72311)\"/></svg>",
"clickableShapes": [
{
"targetId": "#svg_i",
"action": "click",
"payload": "http://www.google.com",
"payloadType": "str",
"topic": "#svg_i"
}
],
"smilAnimations": [],
"bindings": [],
"showCoordinates": false,
"autoFormatAfterEdit": false,
"showBrowserErrors": false,
"outputField": "payload",
"editorUrl": "//drawsvg.org/drawsvg.html",
"directory": "",
"panning": "disabled",
"zooming": "disabled",
"panOnlyWhenZoomed": false,
"doubleClickZoomEnabled": false,
"mouseWheelZoomEnabled": false,
"name": "",
"x": 120,
"y": 60,
"wires": [
[
"e6a43abb.2208c8"
]
]
},
{
"id": "ff128f4a.e252",
"type": "ui_group",
"z": "",
"name": "SVG",
"tab": "9f9846f6.57ce98",
"order": 1,
"disp": true,
"width": "23",
"collapse": false
},
{
"id": "9f9846f6.57ce98",
"type": "ui_tab",
"z": "",
"name": "Background",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]
If you are still searching a solution, "modal dialog" is what you are looking for. Try this:
https://discourse.nodered.org/t/how-to-show-modal-dialog-in-template-node/611/8

Azure media services encoding failed with error : 0x80131040

I have some Azure media encoding jobs failing with the below error.
This is an error from azure backend side after the job has been submitted successfully.
Task 'encode', Error : ErrorProcessingTask : Unexpected error when
setting up the Windows Azure Media Encoder task workflow:Could not
load file or assembly 'Microsoft.WindowsAzure.MediaServices.Platform,
Version=2.10.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or
one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT:
0x80131040)
Any idea what is happening here?
I found out that for some reason using the old encoding job preset names like H264 Adaptive Bitrate MP4 Set 720p and the old processor name Windows Azure Media Encoder do not work anymore. Maybe it is temporary maybe not
I fixed the issue by using the processor name Media Encoder Standard and using a job config string like :
{
"Version": 1.0,
"Codecs": [
{
"KeyFrameInterval": "00:00:02",
"StretchMode": "AutoSize",
"H264Layers": [
{
"Profile": "Auto",
"Level": "auto",
"Bitrate": 3400,
"MaxBitrate": 3400,
"BufferWindow": "00:00:05",
"Width": 1280,
"Height": 720,
"BFrames": 3,
"ReferenceFrames": 3,
"AdaptiveBFrame": true,
"Type": "H264Layer",
"FrameRate": "0/1"
},
{
"Profile": "Auto",
"Level": "auto",
"Bitrate": 2250,
"MaxBitrate": 2250,
"BufferWindow": "00:00:05",
"Width": 960,
"Height": 540,
"BFrames": 3,
"ReferenceFrames": 3,
"AdaptiveBFrame": true,
"Type": "H264Layer",
"FrameRate": "0/1"
},
{
"Profile": "Auto",
"Level": "auto",
"Bitrate": 1500,
"MaxBitrate": 1500,
"BufferWindow": "00:00:05",
"Width": 960,
"Height": 540,
"BFrames": 3,
"ReferenceFrames": 3,
"AdaptiveBFrame": true,
"Type": "H264Layer",
"FrameRate": "0/1"
},
{
"Profile": "Auto",
"Level": "auto",
"Bitrate": 1000,
"MaxBitrate": 1000,
"BufferWindow": "00:00:05",
"Width": 640,
"Height": 360,
"BFrames": 3,
"ReferenceFrames": 3,
"AdaptiveBFrame": true,
"Type": "H264Layer",
"FrameRate": "0/1"
},
{
"Profile": "Auto",
"Level": "auto",
"Bitrate": 650,
"MaxBitrate": 650,
"BufferWindow": "00:00:05",
"Width": 640,
"Height": 360,
"BFrames": 3,
"ReferenceFrames": 3,
"AdaptiveBFrame": true,
"Type": "H264Layer",
"FrameRate": "0/1"
},
{
"Profile": "Auto",
"Level": "auto",
"Bitrate": 400,
"MaxBitrate": 400,
"BufferWindow": "00:00:05",
"Width": 320,
"Height": 180,
"BFrames": 3,
"ReferenceFrames": 3,
"AdaptiveBFrame": true,
"Type": "H264Layer",
"FrameRate": "0/1"
}
],
"Type": "H264Video"
},
{
"Profile": "AACLC",
"Channels": 2,
"SamplingRate": 48000,
"Bitrate": 128,
"Type": "AACAudio"
}
],
"Outputs": [
{
"FileName": "{Basename}_{Width}x{Height}_{VideoBitrate}.mp4",
"Format": {
"Type": "MP4Format"
}
}
]
}

fabric on nodeJS, No images rendering at all

The issue is on Ubuntu 14.04:
NodeJS: 0.10.32
Canvas: 1.3.6
Fabric: 1.6.0-rc.1
Example JSON:
{
"objects": [{
"id": 0,
"name": "1452525510_death_star.svg",
"type": "image",
"originX": "left",
"originY": "top",
"left": 78,
"top": 21,
"width": 512,
"height": 512,
"fill": "rgb(0,0,0)",
"stroke": null,
"strokeWidth": 1,
"strokeDashArray": null,
"strokeLineCap": "butt",
"strokeLineJoin": "miter",
"strokeMiterLimit": 10,
"scaleX": 0.46,
"scaleY": 0.46,
"angle": 0,
"flipX": false,
"flipY": false,
"opacity": 1,
"shadow": null,
"visible": true,
"clipTo": null,
"backgroundColor": "",
"fillRule": "nonzero",
"globalCompositeOperation": "source-over",
"transformMatrix": null,
"_controlsVisibility": {
"tl": false,
"tr": true,
"br": true,
"bl": false,
"ml": true,
"mt": false,
"mr": false,
"mb": true,
"mtr": true
},
"src": "http://somedomain.com/media/patterns/users/1fb158157a882d6a4c983ddc401101d1.svg",
"filters": [{
"type": "Tint",
"color": "#c485c4",
"opacity": 1
}],
"crossOrigin": "",
"alignX": "none",
"alignY": "none",
"meetOrSlice": "meet"
}, {
"id": 1,
"name": "Baby inside",
"type": "image",
"originX": "left",
"originY": "top",
"left": 102,
"top": 290,
"width": 470,
"height": 427,
"fill": "rgb(0,0,0)",
"stroke": null,
"strokeWidth": 1,
"strokeDashArray": null,
"strokeLineCap": "butt",
"strokeLineJoin": "miter",
"strokeMiterLimit": 10,
"scaleX": 0.5,
"scaleY": 0.5,
"angle": 0,
"flipX": false,
"flipY": false,
"opacity": 1,
"shadow": null,
"visible": true,
"clipTo": null,
"backgroundColor": "",
"fillRule": "nonzero",
"globalCompositeOperation": "source-over",
"transformMatrix": null,
"_controlsVisibility": {
"tl": false,
"tr": true,
"br": true,
"bl": false,
"ml": true,
"mt": false,
"mr": false,
"mb": true,
"mtr": true
},
"src": "http://somedomain.com/media/patterns/12.png",
"filters": [{
"type": "Tint",
"color": "#FFFFFF",
"opacity": 1
}],
"crossOrigin": "",
"alignX": "none",
"alignY": "none",
"meetOrSlice": "meet"
}],
"background": "#b0b0b0",
"backgroundImage": {
"id": 0,
"name": "",
"type": "image",
"originX": "left",
"originY": "top",
"left": 0,
"top": 0,
"width": 470,
"height": 574,
"fill": "rgb(0,0,0)",
"stroke": null,
"strokeWidth": 1,
"strokeDashArray": null,
"strokeLineCap": "butt",
"strokeLineJoin": "miter",
"strokeMiterLimit": 10,
"scaleX": 1,
"scaleY": 1,
"angle": 0,
"flipX": false,
"flipY": false,
"opacity": 1,
"shadow": null,
"visible": true,
"clipTo": null,
"backgroundColor": "",
"fillRule": "nonzero",
"globalCompositeOperation": "source-over",
"transformMatrix": null,
"_controlsVisibility": null,
"src": "http://somedomain.com/media/products/121_37_2.jpg",
"filters": [],
"crossOrigin": "",
"alignX": "none",
"alignY": "none",
"meetOrSlice": "meet"
}
Note that this JSON exported with toJSON() has some custom fields: [name, id].
This is from my Node script:
function savetoFile() {
var jsonData = JSONfromAbove;
var out = fs.createWriteStream(filepath);
canvas = fabric.createCanvasForNode(470, 574);
canvas.loadFromJSON(jsonData, function () {
CanvasZoom(parseInt(zoom), function(){
console.log('after zooom');
console.log(canvas.getObjects());
var stream = canvas.createPNGStream();
stream.on('data', function (chunk) {
out.write(chunk);
});
stream.on('end', function () {
out.end();
});
});
});
}
function CanvasZoom(z, callback) {
width = canvas.width;
height = canvas.height;
canvas.setWidth(width*z);
canvas.setHeight(height*z);
canvas.setZoom(z);
canvas.renderAll.bind(canvas);
callback();
}
Facts:
No matter what types of objects I add ('image', 'path',
'path-group') they are not rendering at all, except text and
maybe (I did not tested it) PATHS not from URL's.
In JSON above
there is background img - it doesn't rendering too.
There is no errors at all, however:
The same identical script on OSX works fine BUT:
When I'm trying to add "large" SVG file it gives me:
"image given has not completed loading"
Works fine with HUGE numbers of normal PNG's.
The time to "render" final PNG is proportional to number of objects and their image sizes which might tell that they are loading some kind of well.
I have installed all dependent libs.
Tried to add one object like that ending with the same problem:
fabric.Image.fromURL('http://somedomain.com/media/patterns/12.png', function(oImg, e) {...});
I bet for node-canvas someway failing with URL's.
I spend almost 2 days trying to fix this devilish problem ];>
he issue is that on www.somedomain.com was httpasswd, so it just can't download files but did not throw any errors.
When switched 1.6.0-rc1 to 1.5.X an error occur: "Segmentation Fault".

Adding options in "group" type object in fabricjs canvas

I am trying to load object (group of objects) in canvas, there is no problem with that. But if I want to add some options to loaded object such as scaleX, scaleY, lockScalingX etc. with set method I get an error "Uncaught TypeError: Object Group has no method 'set'". I cannot understand why, I have tried several ways. My code is below -
var json = {
"objects": [{
"type": "group",
"originX": "center",
"originY": "center",
"left": 268,
"top": 203,
"width": 428,
"height": 274,
"fill": "rgb(0,0,0)",
"overlayFill": null,
"stroke": null,
"strokeWidth": 1,
"strokeDashArray": null,
"scaleX": 1,
"scaleY": 1,
"angle": 0,
"flipX": false,
"flipY": false,
"opacity": 1,
"selectable": true,
"hasControls": true,
"hasBorders": true,
"hasRotatingPoint": true,
"transparentCorners": true,
"perPixelTargetFind": false,
"shadow": null,
"visible": true,
"objects": [{
"type": "rect",
"originX": "center",
"originY": "center",
"left": 11,
"top": 37,
"width": 200,
"height": 200,
"fill": "rgba(179,179,179,0.5)",
"overlayFill": null,
"stroke": "#FF0000",
"strokeWidth": 0.1,
"strokeDashArray": null,
"scaleX": 1,
"scaleY": 1,
"angle": 0,
"flipX": false,
"flipY": false,
"opacity": 1,
"selectable": true,
"hasControls": false,
"hasBorders": true,
"hasRotatingPoint": true,
"transparentCorners": true,
"perPixelTargetFind": false,
"shadow": null,
"visible": true,
"rx": 0,
"ry": 0
}, {
"type": "triangle",
"originX": "center",
"originY": "center",
"left": 114,
"top": -37,
"width": 200,
"height": 200,
"fill": "rgba(179,179,179,0.5)",
"overlayFill": null,
"stroke": "#FF0000",
"strokeWidth": 0.1,
"strokeDashArray": null,
"scaleX": 1,
"scaleY": 1,
"angle": 0,
"flipX": false,
"flipY": false,
"opacity": 1,
"selectable": true,
"hasControls": false,
"hasBorders": true,
"hasRotatingPoint": true,
"transparentCorners": true,
"perPixelTargetFind": false,
"shadow": null,
"visible": true
}, {
"type": "circle",
"originX": "center",
"originY": "center",
"left": -114,
"top": 29,
"width": 200,
"height": 200,
"fill": "rgba(179,179,179,0.5)",
"overlayFill": null,
"stroke": "#FF0000",
"strokeWidth": 0.1,
"strokeDashArray": null,
"scaleX": 1,
"scaleY": 1,
"angle": 0,
"flipX": false,
"flipY": false,
"opacity": 1,
"selectable": true,
"hasControls": false,
"hasBorders": true,
"hasRotatingPoint": true,
"transparentCorners": true,
"perPixelTarge,,tFind": false,
"shadow": null,
"visible": true,
"radius": 100
}]
}],
"background": ""
},
objects = json.objects,
canvas = new fabric.Canvas('canvas');
for (var i = 0; i < objects.length; i++) {
var type = fabric.util.string.camelize(fabric.util.string.capitalize(objects[i].type));
type.set({
scaleX: 1.2,
scaleY: 1.2,
lockScalingX: true,
lockScalingY: true
});
type.setCoords();
if (fabric[type].async) {
fabric[type].fromObject(objects[i], function (img) {
canvas.add(img);
});
} else {
canvas.add(fabric[type].fromObject(objects[i]));
}
}
Anyone can help me please?
This exception happens cause the var "type" gets string value which is "Group"
var type = fabric.util.string.camelize(fabric.util.string.capitalize(objects[i].type));
so there is no "set" method in "Group" string as you used:
.set({
scaleX: 1.2,
scaleY: 1.2,})//this is wrong
you can use this :
objects[i].scaleX = 1.2;
objects[i].scaleY = 1.2;
objects[i].lockScalingX = 1.2;
objects[i].lockScalingY = 1.2;
and here the JSfiddle

Resources