Dev Sanctum

Technology architecture, web programming and Internet

  • Home
  • About

12

Feb

Embedding Inline Images in HTML

Posted by RyanTxr  Published in Internet, Programming, Tech, Windows, yahoo

Embed An Image in HTML

Web development often requires us to do strange things to get something done. The Yahoo Avatars API (which is undocumented) sends the small version of your avatar back as Base64 encoded string.  You cannot just do am IMG link to this to get it to display in the browser.  I was doing a small example using this API and I needed to display the image.  In FireFox, this is easy.

XHTML/HTML

<img src=”data:image/png;base64,base64_data_goes_here“>

CSS

background-image: url(data:image/png;base64,base64_data_goes_here)

Voila, you are done.

This isn’t so easy in IE.  Microsoft Internet Explorer does not support the data mechanism for embedding images.

A simple solution is to create a simple web service which accepts the base64 data and returns it as an image.  However, this requires a separate call back to the server to get the image.

PHP Example

$b = base64_decode($_GET['img']);
header(’Content-Type: image/jpg’);
print $b;

RFC822 Solution

The second solution is to use a little known facility in Internet Explorer.   Firefox does not need this solution so whatever application is outputting the HTML needs to send different information based on what browser is in use.  Internet Explorer  has the ability to save an HTML page with all its resources as a single file.  It does this by using RFC822 which was originally created for email. Use MHTML and VML to create the references and embed the data.

Using this approach, all the resources and the HTML are packed into a single file. The file is separated into multiple parts where each part is one resource.  In the HTML part, it is possible to refer to the resources in the other parts almost as if they were files.

Getting this to work was tricky.  I wrote the code as a FireFox only page.  It took quite a while to get this working and it was not obvious what the problem was.

This solution is in PHP.

The first thing to do is to detect IE.  Do it like this:

if (eregi("MSIE",$_SERVER['HTTP_USER_AGENT'])) $MHTML=true;
else $MHTML = false;

Now you can check the variable $MHTML for true or false when different output is needed.

Next, output a header to tell the browser what type of content this is.

if($MHTML){
  //see http://www.w3schools.com/media/media_mimeref.asp
  //for details about Content-type:message/rfc822
  header('Content-type:message/rfc822');
}

Output some more headers to turn of caching.

header('Cache-Control: no-cache');
header('Cache-Control: no-store');
header('Cache-Control: private');

Now for the weird stuff.  The following code segment only gets generated for IE.  It sets up the MIME version we want to use and starts marking off the multiple parts of the file. The boundary of each file part is indicated by “—-=_NextPart”.

<?php if($MHTML) : ?>
MIME-Version: 1.0
Content-Type: multipart/related; boundary="----=_NextPart"

------=_NextPart
Content-Location: file:///X:/
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="us-ascii"
<?php endif ?>

<!doctype html public '-//w3c//dtd html 4.01//en' 'http://www.w3.org/tr/html4/strict.dtd'>
<html xmlns:v=   "urn:schemas-microsoft-com:vml">
<head>

The first part of the multi=part document is the HTML itself. Notice the extra line before —–=_NextPart. If you do not have a blank line here, this will not work. Also, the blank line before ‘doctype’ MUST be there.

The HTML tag references Microsoft VML which is part of what is used to render the image.  Throughout the example, you should notice that all the attributes are written with two or more spaces after the ‘=’.  For some reason, this is necessary.  The attribute :

v=   "urn:schemas-microsoft-com:vml"

Must include at least 2 spaces after the = or it will not work.  This drove me nuts until I figured that out.

<title>Test Embedded Image</title>

Nothing special here.

Now for some more special stuff.

<style type=   "text/css">
v\:* {behavior:url(#default#VML);display:inline-block;}
</style>

Again, notice the spaces after the ‘=’.

This style tells HTML to use VML to render the image.

<?php if($MHTML):?>
<v:shape style=3D"width:16px;height:16px;" ><v:imagedata src=  my_jpg_image  /></v:shape>
<?php else : ?>
<img src=   "data:image/jpg;base64,base64_image_data_goes_here">
<?php endif ?>

The above will render the image in IE or non-IE as needed. Notice the attribute v:imagedata src= my_jpg_image. The name my_jpg_image can be any name you want. So long as it matches the name in the data section of the document.

Finally, after the <html> tag, the image data is included. Remember to leave a blank line before the —–=_NextPart marker.

</html>

<?php if($MHTML):?>

------=_NextPart
Content-Location: file:///X:/my_jpg_image
Content-Transfer-Encoding: base64
Content-Type: image/jpg

<?php echo $small ?>
<?php endif ?>

Notice “Content-Location: file:///X:/my_jpg_image”. This names this section as if it is a file. This has to match the v:imagedata attribute of v:shape.

You can try out this example: Show Yahoo Avatar.

PHP source code: showavatar.php

no comment

10

Dec

Yahoo Layoff

Posted by RyanTxr  Published in Tech, yahoo

It had to happen.  Huge layoffs at Yahoo.  This was in the cards ever since the whole Microsoft buy thing started.  Why did Microsoft want to buy Yahoo?  I’m sure there are parts of the business they wanted.  More importantly, they saw that there was value if they could buy Yahoo at $34.  Yahoo held out for $37 an the rest was history.  Microsoft said no way.  It is easy for anyone to sit back in retrospect and say what a stupid move that was.  From a stockholder perspective, Yahoo at $34 would have awesome.  Now, it can be had for a third of that. Yahoo had lost the search war.  And it was unrealistic to expect that market share could be easily taken back from Google.  Yahoo decided on going after display advertisement and building out an exchange to handle the business not only for itself, but for others as well.  The thing is this.  While it is true that display ads account for more total revenue than search ads, the display ad business is quite fragmented.  Whereas Google pretty much owns the search ad business.  Was it reasonable to expect that Yahoo could somehow take over the display ad business to any degree?  I did not see how that would be possible.  So, given that Yahoo would not get any more search business and there was little chance it would get more display ad business, the entire thing was destined to falter.  There just was not enough time.

Add to all of this the significant reduction in Internet advertising because of the faltering US economy and you had a situation where layoffs had to happen.  As distasteful as they are, anyone running a business would do the same thing.

If Yahoo survives long term, it will be better because of this.  However, don’t think that this is all good and no bad.  This is a set back.  But the set back is in the business model and company revenue, not the staffing levels.

My time at Yahoo was relatively short.  But I thoroughly enjoyed it.  The team I worked with was second to none.  I learned a great deal.  And I was able to excite within myself, a passion for this world of software development that had become so mundane in the previous years.

I quite expect that the spirit of hack that I (re)learned at yahoo will stay with me.  It is one thing I can bring with me elsewhere.

Check back with me for some cool technology stuff.

no comment

24

Nov

First Pass at Yahoo Application Platform

Posted by RyanTxr  Published in Internet, Programming, Tech, Uncategorized, yahoo

I took a look at the Yahoo Application Platform.  The idea of building applications that can run withing Yahoo is very intriguing.  Obviously, any application that would run within Yahoo would include several restrictions.  Afterall, Yahoo won’t open up their environment without making sure it was secure and stable.

The first thing to know is that the application only partially runs within Yahoo.  It actually runs on the developer’s server. The developer must have access to a server that is on the internet.  Access to the root folder of that domain is required to authenticate they keys.  This process is intended to maintain security of the keys and to ensure that if someone steals a key, the key thief won’t be able to use the key without access to the domain.

Yahoo users access the application as if they run within Yahoo and Yahoo, in turn, interacts with the application for them.  It does this so that it can sanitize the interaction and make it secure.  The other side of this is that is does not have all the capabilities of a standard web application.  Before I get into that, let me cover some of the basics.

A Yahoo Open Application can access user data like the lists of friends or activity updates.  This is a formidable reason to use the Yahoo Application Platform as it can create an enormous viral effect if done right.

The Small View

Let me start by talking about the visual parts of a Yahoo Open Application.  A Yahoo Open Application has two views.  This means that it has two ways of looking at the same application.  The small view is a small minimal sized view that is meant to be hosted in another page.  The intent is for Yahoo users to be able to put these small views onto Yahoo pages like the Yahoo front page and profiles.  At this point (Nov 23 2008), this isn’t possible as those Yahoo properties have not been upgraded to allow deployment of these types of modules.  But that should not stop someone from making one and trying it out.  It should be noted that the small view is fairly static.  It has no JavaScript so it cannot be interactive and dynamic like an Ajax application.  It does have some capability to be customized for each user seeing it.

For discussion purposes, I’m thinking of a “My Favorite Team Score” application that lets a user choose their favorite team.  And it shows the score for the last game that the team played.

When the small view is first created, this is only the default view.  The small view is cached on a per user basis.  That’s right.  Each user who installs the application gets their own cached version of the small view.  And the application can update the small view from another application that runs on the server.  I’ll admit that I don’t have all the answers.  I have en expectation that someone could use a cron job to update the small view.  I still have to verify this.  The small view is intended to entice a person to go to the full application

The Canvas View

Then there is the canvas view.  This is sometimes referred to as the full view.  The terms canvas view and full view This is more like a standard web application although it still has some limitations.  Remember that this application appears to live entirely inside Yahoo.  Therefore, an application can deliver content from outside Yahoo to Yahoo users.  The canvas view is 760 px wide and unlimited height.  The canvas view does support limited JavaScript.  The one downside I see is that external JavaScript is not supported.  This means no YUI, jQuery etc unless you are willing to paste all the code into the page itself.

This is the part that got me.  The canvas view is not necessarily a single page.  In fact, the canvas view can present any page from the developer’s server.  There may be some limits on where the page is located.  But I know for sure that if all the pages are located in the same directory on the server, this will work.

YML - Yahoo Markup Language

No discussion of the application platform would be complete without mentioning YML.  YML provides tags which access social data and provide other functionality for open applications.  Review the full list of YML tags for a complete description.  I will only talk about a few of them.

Each YML tag looks like this: <yml:tagname …>.  For example, <yml:a> is analagous to the HTML tag <a> which provides clikckable links to other pages.

Tag <yml:a> attributes

view - this is the name of the view.  Valid values are YahooFullView or YahooSmallView.  YahooSmallView points to the small view.  YahooFullView can point to the default canvas view page or any other page that is colocated with the default full view.  I discovered that I can add additional path information after YahooFullView to point to other files in the same directory.  So far I have only been able to point to other php files, not html.  And it does not allow the content output of that other file to contain <title> or <meta> tags.  It may prevent other tags.

<yml:a view=”YahooFullView” >Link to full view</yml:a>

<yml:a view=”YahooFullView/other.php”>Link to other page in full view</yml:a>

params - Any additional parameters included in this attribute are appended to the end of the HTTP request string.

replace -This is the ID of a DOM node to replace with the output of the view as requested.  The entire DOM node is replaced.  And example of this would be replacement of a DIV with an IMG.  Of course, there is no restriction on the node type.

insert - This is the ID of a DOM node whose contents are replaced.  The DOM node itself remains but its contents are changed.  An example of this would be putting new content into a DIV that already exists in the DOM.

Tag <yml:name>

This tag resolves to the name of a user.  It can resolve to the name of the viewer or the owner.  If you are looking at the application on your own page you are the owner.  If someone else is looking at your profile, they are a viewer.  Therefore, the tag will resolve differently for those two situations.

<yml:name uid=“viewer” linked=“true” capitalize=“true” useyou=“false”/>

linked - this is a boolean value.  If set to true, the tag is rendered as a link to the profile.

useyou - If this is set to true, the tag renders the word you instead of the user’s name if the user is the viewer.

reflexive - This attribute is used together with the ‘useyou’ attribute. If set to true, renders ‘yourself’ instead of ‘you’

capitalize - If true, makes the first letter uppecase.

uid - Use “viewer” to represent the name of the person viewing the application.


continue reading "First Pass at Yahoo Application Platform"

no comment

Advertising

  • Computing eBooks

Categories

  • Drupal
  • Internet
  • LINUX
  • PHP
  • PrepaidCards
  • Programming
  • Social Media
  • Tech
  • Uncategorized
  • webhooks
  • Windows
  • yahoo

Archives

  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008

Admin

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

x-ads

Recent Post

  • Build It and the will not come
  • They Sit And Wait
  • 6 Commandments for developers
  • Making a drupal module
  • Terms Of Service Agreements
  • Sears and Social Media
  • Why I Don’t Allow Analytics
  • Use Twitter to build ecommerce customers
  • Object oriented CSS
  • Uses for the Strategy Pattern

Recent Comments

  • Stoke Directorys in Norton Antivirus is a pain
  • Jesse Gibbs in 6 Commandments for developers
  • Gregg Sporar in 6 Commandments for developers
  • Prashant in Making a drupal module
  • kunal.dabir in Facebook drops support for IE6
  • progrium in Getting to Barcamp Orlando
  • doctor in Norton Antivirus is a pain
  • progrium in Webhooks First Steps
  • Ross Haskell in Surveying Live Chat Solutions
  • kunal.dabir in Being a Technical Architect
© 2007 Dev Sanctum
Theme by Wired Studios, courtesy of Corvette Garage
Valid XHTML | Valid CSS 3.0
Powered by Wordpress