SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Images from anywhere ,[object Object]
[object Object],[object Object],[object Object],The problem
The solution ,[object Object],[object Object],[object Object],[object Object]
The namespace 1   var  Instimage  =  { 2   pending: [], 3   canceled:  false , 4   search:  "" , 5   loading:  new   Element ( 'img' , {src: '/loading.gif' , id: 'loading' }), 6   preload :  function () { ... }, 7   //etc... 8  }
Preload the images 1   preload :  function ( img ){ 2   var  image  =   new   Image () 3   image.onload  =   this .goodImg 4   image.onerror  =   this .goodImg 5   this .cancel.delay( 10000 ,  this ) 6   image. src   =  img 7  }
A little scope 1   goodImg :  function () { 2   if ( this . width   >   200   &&   this . height   >   150   &&   ! Instimage.canceled)  3   Instimage.resize( this ).addClass( 'virgin' ).inject( 'images' ) 4   } 5   Instimage.pending. pop () 6   Instimage.inform() 7  }
The storage API 1   resize :  function ( img ){ 2   img  =   $ (img).store( 'meta' , {width: img. width , height: img. height }) 3   if (img. width   >  img. height ) { 4   var  width  =   200 5   var  height  =  ( 200  / img. width )  *  img. height 6   }  else  { 7   var  height  =   200 8   var  width  =  ( 200  / img. height )  *  img. width 9   } 10   return  img.setStyles({width: width, height: height}) 11  }
Some more scope 1   inform :  function () { 2   $$ ( '#images img.virgin' ).each( function (i){ 3   i.removeClass( 'virgin' ) 4   this .img2JSON(i) 5   i.addEvent( 'click' ,  function (){ 6   Instimage.cancel() 7   $ ( 'src' ).set( 'value' ,  this . src ) 8   Instimage.explode( this ) 9   new   Fx.Scroll ( window ).toElement( 'form' ) 10   }) 11   }, Instimage) 12   if ( this .pending. length   ==   0 ) { 13   //Logic to inform the user how we did 14   } 15  }
More storage and XSJSON 1   img2JSON :  function ( img ){ 2   img.addEvent( 'mouseenter' ,  function (){ 3   var  meta  =   this .retrieve( 'meta' ) 4   if ( ! (meta  &&  meta.exif)) { 5   new   Element ( 'script' , {type: 'text/javascript' , src: ' http://img2json.appspot.com/go/?callback=Instimage.meta&url=' + encodeURIComponent( this . src )}).inject( 'body' ) 6   $ ( 'stats' ).grab(Instimage.loading,  'top' ) 7   }  else 8   Instimage.meta(meta) 9   }) 10  }
FX, chaining & pseudo 1   explode :  function ( img ) { 2   if (img.hasClass( 'exploded' )) { 4   new   Fx.Tween (img, { 5   property:  'opacity' ,  6   onComplete :  function (){ 7   Instimage.resize(img).removeClass( 'exploded' ).setStyle( 'position' ,  'exploded' ).fade( 'show' ) 8   } 9   }). start ( 0 ) 10   }  else  { 11   var  pos  =  img.getPosition( 'images' ) 12   var  size  =  img.retrieve( 'meta' ) 13   img.addClass( 'exploded' ) 15   img.set( 'morph' , {duration:  'long' , transition:  'bounce:out' }); 16   img.setStyles.delay( 500 , img, {top:pos. y , left:pos. x }) 17   img.morph.delay( 500 , img, { top: 40 , left: 0 , position:  'absolute' ,   width:size. width , height:size. height }) 18   } 19   $$ ( '#images img:not(.exploded)' ).fade() 20  }
Events and logic 1   if (Instimage.search  !=   $ ( 'search' ). value ) { 2   Instimage.search  =   $ ( 'search' ). value 3   src  =   ' http://images.google.com/images?q=' + encodeURIComponent(Instimage.search ) 4  } 5   if (src. test ( /  (jpg|jpeg|gif|png)$/ )) { 6   Instimage.preload(src) 7  }  else  { 8   new   Request.JSON ({ 9   onSuccess :  function ( json ) { 10   Instimage.pending  =  json 11   if (json. length   ==   0 ) 12   Instimage.inform() 13   json.each(Instimage.preload, Instimage) 14   }, 15   onFailure :  function () { 16   $ ( 'loading' ).dispose() 17   }, 18   data: { src: src } 19   }).get( '/instimage/scrape' ) 20  }
A little bit of ruby 1   def   scrape 2   provides  :json 3   root  =  params[ :src ][ /^(https?:  .+?  ).+/ ,  1 ] 4   if  root  =~   /images  google  com/ 5   images  =  open(params[ :src ]).read.scan( /dyn  Img  ".*?",".*?",".*?","(.+?)"/ ).flatten 6   else 7   begin 8   parsed  =   Hpricot (open(params[ :src ])) 9   images  =  (parsed / "img" ).map  do  | i |  10   rel(i[ 'src' ]) 11   end .flatten.uniq 12   images  +=  (parsed / "a" ).map  do  | a | 13   src  =  a[ 'href' ] 14   next   unless  src  =~   /  (jpg|jpeg|gif|png)$/ 15   rel(src) 16   end .flatten.uniq 17   rescue 18   images  =  [] 19   end 20   end 21   display images 22   end
Conclusion ,[object Object],[object Object],[object Object],[object Object]

Weitere ähnliche Inhalte

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Empfohlen

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Chris Van Pelt: Instimage and MooTools (SF JS #3)

  • 1.
  • 2.
  • 3.
  • 4. The namespace 1 var Instimage = { 2 pending: [], 3 canceled: false , 4 search: "" , 5 loading: new Element ( 'img' , {src: '/loading.gif' , id: 'loading' }), 6 preload : function () { ... }, 7 //etc... 8 }
  • 5. Preload the images 1 preload : function ( img ){ 2 var image = new Image () 3 image.onload = this .goodImg 4 image.onerror = this .goodImg 5 this .cancel.delay( 10000 , this ) 6 image. src = img 7 }
  • 6. A little scope 1 goodImg : function () { 2 if ( this . width > 200 && this . height > 150 && ! Instimage.canceled) 3 Instimage.resize( this ).addClass( 'virgin' ).inject( 'images' ) 4 } 5 Instimage.pending. pop () 6 Instimage.inform() 7 }
  • 7. The storage API 1 resize : function ( img ){ 2 img = $ (img).store( 'meta' , {width: img. width , height: img. height }) 3 if (img. width > img. height ) { 4 var width = 200 5 var height = ( 200 / img. width ) * img. height 6 } else { 7 var height = 200 8 var width = ( 200 / img. height ) * img. width 9 } 10 return img.setStyles({width: width, height: height}) 11 }
  • 8. Some more scope 1 inform : function () { 2 $$ ( '#images img.virgin' ).each( function (i){ 3 i.removeClass( 'virgin' ) 4 this .img2JSON(i) 5 i.addEvent( 'click' , function (){ 6 Instimage.cancel() 7 $ ( 'src' ).set( 'value' , this . src ) 8 Instimage.explode( this ) 9 new Fx.Scroll ( window ).toElement( 'form' ) 10 }) 11 }, Instimage) 12 if ( this .pending. length == 0 ) { 13 //Logic to inform the user how we did 14 } 15 }
  • 9. More storage and XSJSON 1 img2JSON : function ( img ){ 2 img.addEvent( 'mouseenter' , function (){ 3 var meta = this .retrieve( 'meta' ) 4 if ( ! (meta && meta.exif)) { 5 new Element ( 'script' , {type: 'text/javascript' , src: ' http://img2json.appspot.com/go/?callback=Instimage.meta&url=' + encodeURIComponent( this . src )}).inject( 'body' ) 6 $ ( 'stats' ).grab(Instimage.loading, 'top' ) 7 } else 8 Instimage.meta(meta) 9 }) 10 }
  • 10. FX, chaining & pseudo 1 explode : function ( img ) { 2 if (img.hasClass( 'exploded' )) { 4 new Fx.Tween (img, { 5 property: 'opacity' , 6 onComplete : function (){ 7 Instimage.resize(img).removeClass( 'exploded' ).setStyle( 'position' , 'exploded' ).fade( 'show' ) 8 } 9 }). start ( 0 ) 10 } else { 11 var pos = img.getPosition( 'images' ) 12 var size = img.retrieve( 'meta' ) 13 img.addClass( 'exploded' ) 15 img.set( 'morph' , {duration: 'long' , transition: 'bounce:out' }); 16 img.setStyles.delay( 500 , img, {top:pos. y , left:pos. x }) 17 img.morph.delay( 500 , img, { top: 40 , left: 0 , position: 'absolute' , width:size. width , height:size. height }) 18 } 19 $$ ( '#images img:not(.exploded)' ).fade() 20 }
  • 11. Events and logic 1 if (Instimage.search != $ ( 'search' ). value ) { 2 Instimage.search = $ ( 'search' ). value 3 src = ' http://images.google.com/images?q=' + encodeURIComponent(Instimage.search ) 4 } 5 if (src. test ( / (jpg|jpeg|gif|png)$/ )) { 6 Instimage.preload(src) 7 } else { 8 new Request.JSON ({ 9 onSuccess : function ( json ) { 10 Instimage.pending = json 11 if (json. length == 0 ) 12 Instimage.inform() 13 json.each(Instimage.preload, Instimage) 14 }, 15 onFailure : function () { 16 $ ( 'loading' ).dispose() 17 }, 18 data: { src: src } 19 }).get( '/instimage/scrape' ) 20 }
  • 12. A little bit of ruby 1 def scrape 2 provides :json 3 root = params[ :src ][ /^(https?: .+? ).+/ , 1 ] 4 if root =~ /images google com/ 5 images = open(params[ :src ]).read.scan( /dyn Img ".*?",".*?",".*?","(.+?)"/ ).flatten 6 else 7 begin 8 parsed = Hpricot (open(params[ :src ])) 9 images = (parsed / "img" ).map do | i | 10 rel(i[ 'src' ]) 11 end .flatten.uniq 12 images += (parsed / "a" ).map do | a | 13 src = a[ 'href' ] 14 next unless src =~ / (jpg|jpeg|gif|png)$/ 15 rel(src) 16 end .flatten.uniq 17 rescue 18 images = [] 19 end 20 end 21 display images 22 end
  • 13.