<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[PHP Labware forum — Edit image inside tags? (img attribute values)]]></title>
		<link>https://www.bioinformatics.org/phplabware/forum/viewtopic.php?id=309</link>
		<atom:link href="https://www.bioinformatics.org/phplabware/forum/extern.php?action=feed&amp;tid=309&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Edit image inside tags? (img attribute values).]]></description>
		<lastBuildDate>Tue, 06 Dec 2016 10:04:42 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Edit image inside tags? (img attribute values)]]></title>
			<link>https://www.bioinformatics.org/phplabware/forum/viewtopic.php?pid=875#p875</link>
			<description><![CDATA[<p>Thank you so much. Unfortunately it was too difficult for me to get it working. Would it be possible to hire you to write me the complete wordpress function? </p><p>Please e-mail me or leave me your own.</p>]]></description>
			<author><![CDATA[null@example.com (Marcus Phoenix)]]></author>
			<pubDate>Tue, 06 Dec 2016 10:04:42 +0000</pubDate>
			<guid>https://www.bioinformatics.org/phplabware/forum/viewtopic.php?pid=875#p875</guid>
		</item>
		<item>
			<title><![CDATA[Re: Edit image inside tags? (img attribute values)]]></title>
			<link>https://www.bioinformatics.org/phplabware/forum/viewtopic.php?pid=874#p874</link>
			<description><![CDATA[<p>It is possible to have the feature by using htmLawed&#039;s <a href="http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/htmLawed_README.htm#s3.4.9">hook_tag</a> parameter. The parameter&#039;s value is the name of a custom function that you have to define (include). This function receives two arguments – an element&#039;s name and any attribute name-value pairs – and is called whenever htmLawed encounters an HTML tag (<em>&lt;element...&gt;</em>). Below is some example indicative code to achieve some of the functionality that you are seeking:</p><div class="codebox"><pre class="prettyprint"><code>include(&#039;... /imgClean.php&#039;);
$config = array(... &#039;hook_tag&#039; =&gt; &#039;imgClean&#039; ...);
$out = htmLawed($in, $config ...);

////// imgClean.php
&lt;?php
function imgClean($element, $attr_array=0){

  //// If element is &#039;img&#039;, clean up.
  
  // Remove any height attribute; set width to &#039;100%&#039;, class to &#039;aligncenter&#039;,
  // and remove URL query string for &#039;src&#039; if it points to a Jpeg 
  
  if($element = &#039;img&#039; and is_array($attr_array)){
    if(array_key_exists(&#039;class&#039;, $attr_array)){
      $attr_array[&#039;class&#039;] = &#039;aligncenter&#039; ;
    }
    if(array_key_exists(&#039;height&#039;, $attr_array)){
      unset($attr_array[&#039;height&#039;]);
    }
    if(array_key_exists(&#039;width&#039;, $attr_array)){
      $attr_array[&#039;width&#039;] = &#039;100%&#039;;
    }
    if(array_key_exists(&#039;src&#039;, $attr_array)){
      $attr_array[&#039;src&#039;] = preg_replace(&#039;`\.(jpg|jpeg)\?.+`i&#039;, &#039;.\\1&#039;, $attr_array[&#039;src&#039;]);
    }
  }
  
  //// Return
  
  // If second argument is not received, it means a closing tag is being handled
  
  if(is_numeric($attr_array)){
    return &quot;&lt;/$element&gt;&quot;;
  }

  // Prepare and return tag (element with any attribute string)
  
  $attr_string = &#039;&#039;;
  foreach($attr_array as $k=&gt;$v){
    $attr_string .= &quot; {$k}=\&quot;{$v}\&quot;&quot;;
  }

  static $empty_elements = array(&#039;area&#039;, &#039;br&#039;, &#039;col&#039;, &#039;command&#039;, &#039;embed&#039;, &#039;hr&#039;, &#039;img&#039;, &#039;input&#039;, &#039;isindex&#039;, &#039;keygen&#039;, &#039;link&#039;, &#039;meta&#039;, &#039;param&#039;, &#039;source&#039;, &#039;track&#039;, &#039;wbr&#039;);

  return &quot;&lt;{$element}{$attr_string}&quot;. (in_array($element, $empty_elements) ? &#039; /&#039; : &#039;&#039;). &#039;&gt;&#039;;
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (patnaik)]]></author>
			<pubDate>Sat, 03 Dec 2016 03:21:34 +0000</pubDate>
			<guid>https://www.bioinformatics.org/phplabware/forum/viewtopic.php?pid=874#p874</guid>
		</item>
		<item>
			<title><![CDATA[Edit image inside tags? (img attribute values)]]></title>
			<link>https://www.bioinformatics.org/phplabware/forum/viewtopic.php?pid=873#p873</link>
			<description><![CDATA[<p>Hello, I use htmLawed on WordPress posts and works great. </p><div class="codebox"><pre class="prettyprint"><code>include_once ( TEMPLATEPATH . &#039;/htmLawed.php&#039; ); // 
function clean_the_content( $content )
{
    $szPostContent = $content;
    $szRemoveFilter = array( &quot;~&lt;font[^&gt;]*&gt;~&quot;, &quot;~&lt;/font&gt;~&quot;, &quot;~&lt;div[^&gt;]*&gt;~&quot;, &quot;~&lt;/div&gt;~&quot;, &quot;~&lt;span[^&gt;]*&gt;~&quot;, &quot;~&lt;/span&gt;~&quot;, &quot;~&lt;table[^&gt;]*&gt;~&quot;, &quot;~&lt;/table&gt;~&quot;, &quot;~&lt;script[^&gt;]*&gt;~&quot;, &quot;~&lt;/script&gt;~&quot;, &quot;~&lt;SCRIPT[^&gt;]*&gt;~&quot;, &quot;~&lt;/SCRIPT&gt;~&quot;);
    $szPostContent = preg_replace( $szRemoveFilter, &#039;&#039; , $szPostContent);
    $szPostContent = htmLawed($szPostContent);
    return $szPostContent;
}
add_filter(&#039;the_content&#039;, &#039;clean_the_content&#039;);</code></pre></div><p>My main problem is that I need to edit inside image tag, is that possible? </p><p>For example: this is by default: </p><div class="codebox"><pre class="prettyprint"><code>&lt;img class=&quot;aligncenter size-full wp-image-33089&quot; src=&quot;https://www.domain.com/image1.jpg?w=474&amp;amp;h=474&quot; alt=&quot;&quot; width=&quot;474&quot; height=&quot;474&quot; /&gt;</code></pre></div><p>And I need it to be:</p><div class="codebox"><pre class="prettyprint"><code>&lt;img class=&quot;aligncenter&quot; src=&quot;https://www.domain.com/image1.jpg&quot; width=&quot;100%&quot; /&gt;</code></pre></div><p>So my question is, can I add custom function or something that it would change the class, width and if possible remove everything after jpg questionmark (.jpg?w=...)</p><p>If it is possible, how to apply it to clean_the_content function?</p>]]></description>
			<author><![CDATA[null@example.com (Marcus Phoenix)]]></author>
			<pubDate>Wed, 30 Nov 2016 05:29:44 +0000</pubDate>
			<guid>https://www.bioinformatics.org/phplabware/forum/viewtopic.php?pid=873#p873</guid>
		</item>
	</channel>
</rss>
