How to read an image from url in python 3 and get the height and width

To read an image directly from url and then reads its size. you can use urllib.request and PIL aka Pillow.
If you don’t have pillow installed. you can use:

  1.  python -m pip install Pillow

and before that you might need to upgrade pip, especially if you get an error

  1.  python -m pip install --upgrade pip

Here is how to read an image from url.

  1.  import urllib.request
  2.  from PIL import Image
  3.  url = 'http://www.example.com/my_image_is_not_your_image.png'
  4.  image = Image.open(urllib.request.urlopen(url))
  5.  width, height = image.size
  6.  print (width,height)
  7.  

If you followed a tutorial that uses urllib2 you can change that to urllib.request in python 3.

‘cp932’ codec can’t encode character ‘\xa1’ in position 62: illegal multibyte sequence

When using print in python with some multibyte character or when decoding from another encoding you might encounter this fatal error:

  1.  Traceback (most recent call last):
  2.   File "skynet.py", line 28, in
  3.   print(skyname_wakeup_word)
  4.  UnicodeEncodeError: 'cp932' codec can't encode character '\xa1' in position 62: illegal multibyte sequence

To sort of fix it, you can use

  1.  skyname_wakeup_word.encode('cp932',"ignore")

This occurs because python can’t convert that character to the traditional windows ansi used in windows terminal (cmd). cp932 is code page 932 the Japanese version of shift-JIS.
Other encodings: cp874, cp936, cp949, cp950, cp1251, cp1252, cp1253, cp1254, cp1255, cp1256, cp1257, cp1258. Source

IE 11 not opening, crashing on Windows 10 after upgrade from windows 7, How to solve

After upgrading from windows 7 to 10,  IE 11 doesn’t open.  I have searched a lot but didn’t find a solution.  One solution suggested it was due to logitech camera’s process monitor. but removing that didn’t solve the problem.   The error log in event viewer was this:

Faulting application name: iexplore.exe, version: 11.0.10240.16412, time stamp: 0x55b99d3f
Faulting module name: ntdll.dll, version: 10.0.10240.16430, time stamp: 0x55c59f92
Exception code: 0xc0000409

After some digging, it turned out it was due to EMET 5.2 Microsoft mitigation service.  seems Microsoft security service breaks its own program.   I uninstalled it, IE 11 worked. I reinstalled it after downloading it again from Microsoft site.  IE 11 stopped working.  I opened EMET notification and went into apps and tested the different checkboxes for IE.  unchecked EAF and leaving other checks worked.

TL;DR;  If you have EMET 5.2 installed, opening EMET, going to APPS -> unchecking EAF in front of Internet Explorer and then OK should make IE work again.  what security implication that means not sure. but Microsoft should fix this soon.

 

Keep pebble time watchface backlight on for longer than 3 seconds

The pebble time watchface dims pretty fast and it only lasts 3 seconds, unfortunately there is no option right to increase that. in watchface it is possible to change this behavior programatically here is how i did it.


  1.   static int seconds;
  2.   static void set_backlight(){
  3.   light_enable_interaction();
  4.   if (seconds<=4)return;
  5.   app_timer_register(3000,set_backlight, NULL);
  6.   }
  7.   static void accel_tap_handler(AccelAxisType axis,int32_t direction) {
  8.   light_enable_interaction();
  9.   seconds = 10;
  10.   app_timer_register(3000,set_backlight, NULL);
  11.   }
  12.   static void main_window_load(Window *window) {
  13.   ...
  14.   accel_tap_service_subscribe(&accel_tap_handler);
  15.   ...
  16.   }
  17.   static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  18.   if (seconds>0)seconds--;
  19.   ...
  20.   }
  21.   static void init() {
  22.   ...
  23.   tick_timer_service_subscribe(SECOND_UNIT, tick_handler);
  24.   ...
  25.   }
  26.