Secciones de la página

Funciones de imágenes img. tol

Funciones

Set ImgGetSet()

Text Img2Div()

Text Img2Htm()

Text ImgGetAlt()

Text ImgGetSrc()

Text ImgGetTit()

Text ImgMap()

Text ImgNormalize()

Tol

Artículos del sitio

Presentación de Tol

Todos los programas

Simuladores visuales

Sitios que me gustan

Por categorías

Algoritmia

Búsqueda y ordenación

Computación fisiológica

Editorial y edición

Gráficos de datos

Herramientas y utilidades

Hipertexto

Informática forense

Lectura óptica de datos

Metaprogramación

No determinista

Ofimática

Recursión e iteración

Reglas y restricciones

Series y estadística









Funciones de imágenes img.tol

Funciones para la manipulación del tag de imágenes del lenguaje Html <img src="..." alt="..." ticle="..." class="..." ...>.

Las funciones de esta página están ordenadas de forma alfabética por las diferentes gramáticas del lenguaje Tol ( Text, Set, Serie, Anything, Code, Date, Real,...) y, dentro de cada gramática, por el nombre de la función. Pueden encontrarse 2 o más funciones con idéntico nombre, pero con distintas maneras de programarse o con diferentes comentarios en diferentes idiomas, estas funciones aparecerán unas a continuación de las otras.

Set ImgGetSet() de con-Q.tv

//////////////////////////////////////////////////////////////////////////////
Set ImgGetSet(Text htmCod)
//////////////////////////////////////////////////////////////////////////////
{
  Text imgTxt = Compact(TxtInside2TagPlus(htmCod, ImgTag, ">"));
  If(imgTxt == "", Empty,
  {
    Text imgRep = Replace(imgTxt, "><", ">"+Char(7)+"<");
    Tokenizer(imgRep, Char(7))
  })
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el conjunto de imagenes de una pieza de codigo Html.",
ImgGetSet);
//////////////////////////////////////////////////////////////////////////////

Text Img2Div() de con-Q.tv

//////////////////////////////////////////////////////////////////////////////
Text Img2Div(Text imgSrc, // Image path
             Text imgAlt, // Alternate text, mandatory
             Text imgTit, // Image title
             Text imgLnk, // Main link
             Text imgLst, // List of links
             Text imgCla, // Image class
             Text imgDef) // Para cuando no hay textos
//////////////////////////////////////////////////////////////////////////////
{
  Text htmImg = Img2Htm(imgSrc, imgAlt, imgTit, imgCla, imgDef);
  
  Text htmTxt = Case
  (
    And(imgAlt != "", imgTit == ""),             imgAlt,
    And(imgAlt == "", imgTit != ""),             imgTit,
    And(imgAlt == "", imgTit == ""),             imgDef,
        imgAlt == imgTit,                        imgAlt,
        TRUE,                        imgTit+": "+imgAlt
  )+". ";
             
  Text htmDes = "<p>"+htmTxt+imgLst+"</p>";

  "\n<div class="+Q(imgCla)+">" +
  "\n  "    + imgLnk + htmImg + "</a>" +
  "\n  "    + htmDes +
  "\n</div><div style="+Q("clear:both")+"></div>\n"
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el codigo Html de una imagen con sus atributos completos rellenando
aquellos que faltan y todo dentro de una estructura Html div.",
Img2Div);
//////////////////////////////////////////////////////////////////////////////

Text Img2Htm() de iForense

//////////////////////////////////////////////////////////////////////////////
Text Img2Htm(Text imgSrc, // Image path
             Text imgAlt, // Alternate text, mandatory
             Text imgTit, // Image title
             Text imgCla, // Image class
             Text imgDef) // Para cuando no hay textos
//////////////////////////////////////////////////////////////////////////////
{
  Text htmSrc =   " src="+Q(imgSrc);

  Text htmCla = " class="+Q(imgCla);

  Text htmAlt = If(imgAlt!="", " alt="+Q(imgAlt),     // Hay alt
                If(imgTit!="", " alt="+Q(imgTit),     // Sin alt pero si title
                               " alt="+Q(imgDef)));   // Sin nada

  Text htmTit = If(imgTit!="", " title="+Q(imgTit),   // Hay title
                If(imgAlt!="", " title="+Q(imgAlt),   // Sin title pero si alt
                               " title="+Q(imgDef))); // Sin nada

  Text htmImg = "\n  <img" + htmSrc + 
                "\n    "   + htmCla +
                "\n      " + htmAlt + 
                "\n    "   + htmTit + " />";

  htmImg
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el codigo Html de una imagen con sus atributos completos rellenando
aquellos que faltan.",
Img2Htm);
//////////////////////////////////////////////////////////////////////////////

Text ImgGetAlt() de iForense

//////////////////////////////////////////////////////////////////////////////
Text ImgGetAlt(Text imgCod)
//////////////////////////////////////////////////////////////////////////////
{ TxtBetween2Tag(ImgNormalize(imgCod), "alt='", "'", TRUE) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna de un codigo Html de una imagen el texto alt de la imagen.",
ImgGetAlt);
//////////////////////////////////////////////////////////////////////////////

Text ImgGetSrc() de iForense

//////////////////////////////////////////////////////////////////////////////
Text ImgGetSrc(Text imgCod)
//////////////////////////////////////////////////////////////////////////////
{ TxtBetween2Tag(ImgNormalize(imgCod), "src='", "'", TRUE) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna de un codigo Html de una imagen la url de la imagen.",
ImgGetSrc);
//////////////////////////////////////////////////////////////////////////////

Text ImgGetTit() de con-Q.tv

//////////////////////////////////////////////////////////////////////////////
Text ImgGetTit(Text imgCod)
//////////////////////////////////////////////////////////////////////////////
{ TxtBetween2Tag(ImgNormalize(imgCod), "title='", "'", TRUE) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna de un codigo Html de una imagen el texto title de la imagen.",
ImgGetTit);
//////////////////////////////////////////////////////////////////////////////

Text ImgMap() de con-Q.tv

//////////////////////////////////////////////////////////////////////////////
Text ImgMap(Set  ctrPdb, // Set of post from a post database
            Text txtPat, // Text pattern for seleccion in alts and title
            Text namCla, // Name for image class
            Text txtDef) // Para cuando no hay textos
//////////////////////////////////////////////////////////////////////////////
{
  Set  imgPdb = EvalSet(ctrPdb, Set(Set objPst)
  {// Si se crean imágenes dinámicas no las ve, sería recursivo en este post
    Set imgSel = ImgGetSet(objPst->pstHtm); 

    EvalSet(imgSel, Set(Text imgCod)
    {
      Text imgSrc = ImgGetSrc(imgCod);
      Text imgAlt = ImgGetAlt(imgCod);
      Text imgTit = ImgGetTit(imgCod);
      Text imgLnk = PhtLinkPost(objPst);
     
      // Text WriteLn(imgSrc+"\n"+imgAlt+"\n"+imgTit+"\n"+imgLnk+"\n");
      SetOfText(imgSrc, imgAlt, imgTit, imgLnk)
    })
  });

  Set  imgGrp = BinGroup("<<", imgPdb);
  Text lowPat = Compact(ToLower(txtPat));
  Set  imgSel = If(lowPat == "", imgGrp, // Todas las imagenes
  { 
    Select(imgGrp, Real(Set imgSet)
    { Or(TextFind(Compact(ToLower(imgSet[2])), lowPat),    // Busca en alt
         TextFind(Compact(ToLower(imgSet[3])), lowPat)) }) // Busca en title
  });
 
  // Clasifica por el path de la imagen reverse
  Set  imgCla = Classify(imgSel, Real(Set a, Set b) { Compare(b[1], a[1]) }); 

  Set  imgCic = EvalSet (imgCla, Text(Set imgSet)
  {
    Text imgSrc = imgSet[1][1];
    Text imgAlt = imgSet[1][2];

    // Solo si title es diferente al alt     
    Text imgTit = If(imgAlt == imgSet[1][3], "", imgSet[1][3]);

    // El primer link
    Text imgLnk = "<"+TxtBetween2Tag(imgSet[1][4], "<", ">", TRUE)+">";

    Text imgLst = Set2Txt(Traspose(imgSet)[4],
      "En ", ".", ", ", " y ", "", "", "", ""); // Todos los links

    Img2Div(imgSrc, imgAlt, imgTit, imgLnk, imgLst, namCla, txtDef)
  });
  SetSum(imgCic)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el codigo Html de un mapa o indice de imagenes extraidas de un
conjunto de post en Html.",
ImgMap);
//////////////////////////////////////////////////////////////////////////////

Text ImgNormalize() de con-Q.tv

//////////////////////////////////////////////////////////////////////////////
Text ImgNormalize(Text imgCod)
//////////////////////////////////////////////////////////////////////////////
{
  Text imgCmp = Compact(imgCod);
  ReplaceTable(imgCmp,
  [[
    [["= ",     "="]],
    [[" =",     "="]],
    [[".'",     "'"]], // Elimina los puntos finales
    [[Char(34), "'"]]
  ]])
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el codigo Html de una imagen normalizado.",
ImgNormalize);
//////////////////////////////////////////////////////////////////////////////

2015 asolver.com | Aviso legal | XHTML | Δ Θ Ξ | Creative Commons | Mapa y funciones del sitio

Tol