<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>Max | MaxVergelli.com</title>
	<atom:link href="https://www.maxvergelli.com/author/max/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.maxvergelli.com</link>
	<description>sourcecode repository</description>
	<lastBuildDate>Fri, 17 Apr 2020 18:23:39 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i2.wp.com/www.maxvergelli.com/wp-content/uploads/2020/04/wp-1586823685141.png?fit=32%2C32&#038;ssl=1</url>
	<title>Max | MaxVergelli.com</title>
	<link>https://www.maxvergelli.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">34603511</site>	<item>
		<title>Create an Excel file in C# without Microsoft Office or Third party plugins</title>
		<link>https://www.maxvergelli.com/create-an-excel-file-in-c-without-microsoft-office-or-third-party-plugins/</link>
					<comments>https://www.maxvergelli.com/create-an-excel-file-in-c-without-microsoft-office-or-third-party-plugins/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Sat, 18 Apr 2020 18:07:00 +0000</pubDate>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[.net-framework]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[dll]]></category>
		<category><![CDATA[epplus5]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[excel-cell]]></category>
		<category><![CDATA[excel-document]]></category>
		<category><![CDATA[excel-row]]></category>
		<category><![CDATA[excel-sheet]]></category>
		<category><![CDATA[excel-workbook]]></category>
		<category><![CDATA[excellibrary]]></category>
		<category><![CDATA[free-dll]]></category>
		<category><![CDATA[free-library]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[libre-office]]></category>
		<category><![CDATA[microsoft-excel]]></category>
		<category><![CDATA[microsoft-office]]></category>
		<category><![CDATA[office]]></category>
		<category><![CDATA[open-source]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[workbook]]></category>
		<category><![CDATA[xls]]></category>
		<category><![CDATA[xlsx]]></category>
		<guid isPermaLink="false">https://www.maxvergelli.com/?p=247</guid>

					<description><![CDATA[<p>How to create an Excel file (XLS / XLSX) in C# without having a copy of Microsoft Office on the server, or other third party plugins installed</p>
<p>The post <a href="https://www.maxvergelli.com/create-an-excel-file-in-c-without-microsoft-office-or-third-party-plugins/">Create an Excel file in C# without Microsoft Office or Third party plugins</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>What I&#8217;m about to say seems paradoxical, but the reality is that in open environments (as in PHP for example) it is often easier and we have less problems in creating or converting files in proprietary systems, compared to what happens on frameworks such as Microsoft&#8217;s .Net; this is the case when we have to create an Excel file (XLS / XLSX) in C# without having a copy of Microsoft Office on the server, or other third party plugins installed, without the right libraries in our project we will have several headaches. A quick solution is to use the open-source library <a href="https://github.com/gustafl/ExcelLibrary" class="aioseop-link">ExcelLibrary</a>. This looks to be a port of the PHP ExcelWriter, it&#8217;s very simple, small and easy to use.</p>



<p><strong>Using ExcelLibrary</strong></p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text/x-csharp&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;C#&quot;,&quot;modeName&quot;:&quot;csharp&quot;}">Workbook workbook = new Workbook();
workbook.Open(&quot;Book1.xlsx&quot;);
Sheet sheet = workbook.Sheet(&quot;Sheet1&quot;);
Row row = sheet.Row(2);
Cell cell = row.Cell(3);
string text = cell.Value;</pre></div>



<p><strong>Main features</strong></p>



<ul><li>No dependencies except .NET Framework 4.5. Easy to include in other solutions.</li><li>Built and extendable with LINQ. Most collections in the library (e.g. <code>Workbook.Sheets</code> or <code>Row.Cells</code>) is of type <code>IEnumerable&lt;T&gt;</code>, which allows you to use LINQ queries to find exactly what you need.</li><li>Respects the visibility of sheets, rows and columns. Set the <code>IncludeHidden</code> option to <code>true</code>to return hidden objects.</li><li>Well-tested. The library is being developed using principles of Test-driven development (TDD). A large set of unit tests verifies that new bugs are not introduced on code changes.</li><li>Well-documented. A software library is only as useful as its documentation.</li></ul>



<p>Another valid alternative is <a href="https://github.com/EPPlusSoftware/EPPlus" class="aioseop-link">EPPLUS5</a>  however it has a new license model from version 5, it&#8217;s still free to use in some cases, but will require a commercial license to be used in a commercial business.</p><p>The post <a href="https://www.maxvergelli.com/create-an-excel-file-in-c-without-microsoft-office-or-third-party-plugins/">Create an Excel file in C# without Microsoft Office or Third party plugins</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/create-an-excel-file-in-c-without-microsoft-office-or-third-party-plugins/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">247</post-id>	</item>
		<item>
		<title>How to convert HDR10+ videos to SDR (for non-HDR devices)</title>
		<link>https://www.maxvergelli.com/how-to-convert-hdr10-videos-to-sdr-for-non-hdr-devices/</link>
					<comments>https://www.maxvergelli.com/how-to-convert-hdr10-videos-to-sdr-for-non-hdr-devices/#comments</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Fri, 17 Apr 2020 13:02:00 +0000</pubDate>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Video Editing]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[device]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[format-conversion]]></category>
		<category><![CDATA[galaxy-s10]]></category>
		<category><![CDATA[hdr]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[mp4]]></category>
		<category><![CDATA[sdr]]></category>
		<category><![CDATA[smartphone]]></category>
		<category><![CDATA[standard-dynamic-range]]></category>
		<category><![CDATA[tv]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[video-conversion]]></category>
		<category><![CDATA[video-editing]]></category>
		<guid isPermaLink="false">https://www.maxvergelli.com/?p=251</guid>

					<description><![CDATA[<p>How to convert HDR10+ videos to SDR, so can be viewed on non-HDR devices with brightful and not washed-out colors</p>
<p>The post <a href="https://www.maxvergelli.com/how-to-convert-hdr10-videos-to-sdr-for-non-hdr-devices/">How to convert HDR10+ videos to SDR (for non-HDR devices)</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>New smartphones like <em>Samsung Galaxy S10</em> and <em>S10+</em> can record videos in HDR10+, a new standard in HDR, which redefine the concept of Higher Dynamic Range (<em><strong>HDR</strong></em>). <a href="https://www.youtube.com/watch?v=aws42wl7cck" target="_blank" aria-label="Watch this video (opens in a new tab)" rel="noreferrer noopener" class="aioseop-link">Watch this video</a> to learn how to record videos in HDR10+, otherwise, continue reading the post&#8230;</p>



<h4><strong>Differences with HDR and how HDR10+ works</strong>&#8230;</h4>



<p>The standard HDR technology adds up the static metadata to the content (*.MP4 video). This will mean that the parameters are applied at the beginning itself and continue throughout. This causes the bright scenes in a movie look too bright and lose detail, while the dark scenes would continue to look dim. In HDR10+ the brightness boundaries of the video clip is configured and changed in a frame by frame manner, the full-color range is added to every scene dynamically no matter whether it contains only dark or only light scenes. </p>



<p>In other words, HDR10+ ensures that you will end up getting the best details in your videos and images.</p>



<h3><strong>How an HDR10+ video is viewed on supported and non-HDR devices</strong></h3>



<p>There is a problem, when viewing an HDR10+ video on a device that does not support the HDR10+ standard, the video will be displayed as in the following image on the left (with washed-out colors), while on a Galaxy S10 smartphone or TV that supports HDR10+ you will see it as in the image on the right</p>



<figure class="wp-block-image size-large"><img loading="lazy" width="800" height="226" src="https://i0.wp.com/www.maxvergelli.com/wp-content/uploads/2020/04/hdr-to-sdr.jpg?resize=800%2C226&#038;ssl=1" alt="" class="wp-image-252" srcset="https://i0.wp.com/www.maxvergelli.com/wp-content/uploads/2020/04/hdr-to-sdr.jpg?w=800&amp;ssl=1 800w, https://i0.wp.com/www.maxvergelli.com/wp-content/uploads/2020/04/hdr-to-sdr.jpg?resize=300%2C85&amp;ssl=1 300w, https://i0.wp.com/www.maxvergelli.com/wp-content/uploads/2020/04/hdr-to-sdr.jpg?resize=768%2C217&amp;ssl=1 768w" sizes="(max-width: 800px) 100vw, 800px" data-recalc-dims="1" /></figure>



<p>So, to view an HDR10+ video on an unsupported device, <strong>we must first convert it to a video in SDR (standard dynamic range)</strong> which however must retains the same depth and intensity of colors, without washed-out colors, as the original HDR10+ video.</p>



<h2><strong>How to convert HDR10+ video to SDR on PC</strong></h2>



<p>To make the video conversion from HDR10+ to SDR is very simple on a Samsung Galaxy S10 smartphone, but <strong>in this article I will explain how to convert it on PC</strong> (otherwise, if you want to know how to convert it on Galaxy S10, <a aria-label="read this from Samsung (opens in a new tab)" href="https://www.samsung.com/us/support/answer/ANS00086003/" target="_blank" rel="noreferrer noopener" class="aioseop-link">read this from Samsung</a>).</p>



<p>First of all, you need the <strong>ffmpeg</strong> software, a free command-line tool that converts audio or video formats; from this link <a href="http://ffmpeg.org/download.html" target="_blank" aria-label=" (opens in a new tab)" rel="noreferrer noopener" class="aioseop-link">http://ffmpeg.org/download.html</a> look for &#8220;Get packages &amp; executable files&#8221;, and download the compiled version for your OS (Linux, Windows or Mac).</p>



<h4><strong>Step 1</strong> : <strong>Extract FFMPEG to a folder</strong></h4>



<p>Extract the contents of the zip file to a new folder in &#8220;C:\ffmpeg\&#8221; (this is a windows path, but you can change it at your convenience).</p>



<h4><strong>Step 2</strong> : <strong>Create a Batch file and copy your HDR10+ video to convert</strong></h4>



<p>Create a new file named &#8220;convert.bat&#8221; in &#8220;C:\ffmpeg\bin&#8221; with the following code</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;Shell&quot;,&quot;modeName&quot;:&quot;shell&quot;}">C:\ffmpeg\bin\ffmpeg.exe -i video-input.mp4 -vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -c:v libx265 -crf 22 -preset medium -tune fastdecode video-output.mp4</pre></div>



<p>Then, copy your HDR10+ video in &#8220;C:\ffmpeg\bin&#8221; and rename it in &#8220;video-input.mp4&#8221;</p>



<h4><strong>Step 3</strong> : <strong>Open a command prompt and execute the batch</strong></h4>



<p>Now, press <strong>Windows</strong> button+<strong>R</strong> to <strong>open</strong> the “Run” box. Type “<strong>cmd</strong>” and click “OK” to open a regular Command Prompt. Finally, type &#8220;C:\ffmpeg\bin\convert.bat&#8221; to start the conversion from HDR10+ video to a new SDR video named &#8220;video-output.mp4&#8221;.</p>



<h4><strong>Conversion completed!</strong></h4>



<p>At the end of the conversion, you will find the new converted file in the &#8220;C:\ffmpeg\bin\&#8221; folder. </p>



<p>The new SDR file &#8220;video-output.mp4&#8221; <strong>can be viewed on all non-HDR devices, but with the same brightful colors</strong> as the original HDR10+ video.</p>



<p>Have fun converting your movies! 😀</p><p>The post <a href="https://www.maxvergelli.com/how-to-convert-hdr10-videos-to-sdr-for-non-hdr-devices/">How to convert HDR10+ videos to SDR (for non-HDR devices)</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/how-to-convert-hdr10-videos-to-sdr-for-non-hdr-devices/feed/</wfw:commentRss>
			<slash:comments>14</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">251</post-id>	</item>
		<item>
		<title>Javascript equivalent to PHP __construct</title>
		<link>https://www.maxvergelli.com/javascript-equivalent-to-php-__construct/</link>
					<comments>https://www.maxvergelli.com/javascript-equivalent-to-php-__construct/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Thu, 16 Apr 2020 17:36:00 +0000</pubDate>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[class-constructor]]></category>
		<category><![CDATA[construct]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[constructor-function]]></category>
		<category><![CDATA[constructor-method]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[javascript-class]]></category>
		<category><![CDATA[javascript-construct]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[parameters]]></category>
		<category><![CDATA[php-like]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scripting]]></category>
		<guid isPermaLink="false">https://www.maxvergelli.com/?p=245</guid>

					<description><![CDATA[<p>Constructor method in Javascript class equivalent to PHP, how to run a function in Javascript whenever the object is instantiated.</p>
<p>The post <a href="https://www.maxvergelli.com/javascript-equivalent-to-php-__construct/">Javascript equivalent to PHP __construct</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>The <code>constructor</code> method is a special method for creating and initializing an object created within a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class"><code>class</code></a>. In other words, it&#8217;s a function that runs automatically whenever the object is instantiated.</p>



<p><strong>Using the <code>constructor</code> method</strong></p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;JavaScript&quot;,&quot;modeName&quot;:&quot;js&quot;}">class Person {

  constructor(name) {
    this.name = name;
  }

  introduce() {
    console.log(`Hello, my name is ${this.name}`);
  }

}

const otto = new Person('Otto');

otto.introduce();</pre></div>



<p>If you don&#8217;t provide your own constructor, then a default constructor will be supplied for you. If your class is a base class, the default constructor is empty:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;JavaScript&quot;,&quot;modeName&quot;:&quot;js&quot;}">constructor() {}</pre></div>



<p>If your class is a derived class, the default constructor calls the parent constructor, passing along any arguments that were provided:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;JavaScript&quot;,&quot;modeName&quot;:&quot;js&quot;}">constructor(...args) {
  super(...args);
}</pre></div>



<p>Just as a reminder: the <strong>super</strong> keyword is used to access and call functions on an object&#8217;s parent (more information here <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super" class="aioseop-link">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super</a>)</p>



<p>Look at these other resources on <strong>Javascript constructor</strong>:</p>



<p><a href="https://stackoverflow.com/questions/61213185/javascript-equivalent-to-php-construct">https://stackoverflow.com/questions/61213185/javascript-equivalent-to-php-construct</a></p>



<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor</a></p><p>The post <a href="https://www.maxvergelli.com/javascript-equivalent-to-php-__construct/">Javascript equivalent to PHP __construct</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/javascript-equivalent-to-php-__construct/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">245</post-id>	</item>
		<item>
		<title>How to parse and process HTML/XML in PHP</title>
		<link>https://www.maxvergelli.com/how-to-parse-and-process-html-xml-in-php/</link>
					<comments>https://www.maxvergelli.com/how-to-parse-and-process-html-xml-in-php/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Wed, 15 Apr 2020 16:44:00 +0000</pubDate>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[String Manipulation Algorithms]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[document]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[find-html]]></category>
		<category><![CDATA[grabbing]]></category>
		<category><![CDATA[html-manipulation]]></category>
		<category><![CDATA[html-parser]]></category>
		<category><![CDATA[libxml]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[parsing-html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php-class]]></category>
		<category><![CDATA[php-extension]]></category>
		<category><![CDATA[php-query]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[php7]]></category>
		<category><![CDATA[query-path]]></category>
		<category><![CDATA[simple-html-dom]]></category>
		<category><![CDATA[simple-xml]]></category>
		<category><![CDATA[xml-parser]]></category>
		<category><![CDATA[xml-reader]]></category>
		<guid isPermaLink="false">https://www.maxvergelli.com/?p=239</guid>

					<description><![CDATA[<p>Simple HTML DOM is a great open-source parser: simplehtmldom.sourceforge It treats DOM elements in an object-oriented way, and the new iteration has a lot of coverage for non-compliant code. There are also some great functions like you&#8217;d see in JavaScript, &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/how-to-parse-and-process-html-xml-in-php/" aria-label="How to parse and process HTML/XML in PHP">Read More</a></p>
<p>The post <a href="https://www.maxvergelli.com/how-to-parse-and-process-html-xml-in-php/">How to parse and process HTML/XML in PHP</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Simple HTML DOM is a great open-source parser:</p>



<p><a href="http://simplehtmldom.sourceforge.net/">simplehtmldom.sourceforge</a></p>



<p>It treats DOM elements in an object-oriented way, and the new iteration has a lot of coverage for non-compliant code. There are also some great functions like you&#8217;d see in JavaScript, such as the &#8220;find&#8221; function, which will return all instances of elements of that tag name.</p>



<p>I&#8217;ve used this in a number of tools, testing it on many different types of web pages, and I think it works great.</p>



<p>These are the main features:</p>



<ul><li>HTML DOM parser written in PHP 5+ that lets you manipulate HTML in a very easy way</li><li>Require PHP 5+</li><li>Supports invalid HTML</li><li>Find tags on an HTML page with selectors just like jQuery</li><li>Extract contents from HTML in a single line</li></ul>



<p><strong>How to get HTML elements:</strong></p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">// Create DOM from URL or file
$html = file_get_html('http://www.example.com/');

// Find all images
foreach($html-&gt;find('img') as $element)
       echo $element-&gt;src . '&lt;br&gt;';

// Find all links
foreach($html-&gt;find('a') as $element)
       echo $element-&gt;href . '&lt;br&gt;';</pre></div>



<p><strong>How to modify HTML elements:</strong></p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">// Create DOM from string
$html = str_get_html('&lt;div id=&quot;hello&quot;&gt;Hello&lt;/div&gt;&lt;div id=&quot;world&quot;&gt;World&lt;/div&gt;');

$html-&gt;find('div', 1)-&gt;class = 'bar';

$html-&gt;find('div[id=hello]', 0)-&gt;innertext = 'foo';

echo $html;</pre></div>



<p><strong>Extract content from HTML:</strong></p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">// Dump contents (without tags) from HTML
echo file_get_html('http://www.google.com/')-&gt;plaintext;</pre></div>



<p><strong>Scraping Slashdot:</strong></p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">// Create DOM from URL
$html = file_get_html('http://slashdot.org/');

// Find all article blocks
foreach($html-&gt;find('div.article') as $article) {
    $item['title']     = $article-&gt;find('div.title', 0)-&gt;plaintext;
    $item['intro']    = $article-&gt;find('div.intro', 0)-&gt;plaintext;
    $item['details'] = $article-&gt;find('div.details', 0)-&gt;plaintext;
    $articles[] = $item;
}

print_r($articles);</pre></div><p>The post <a href="https://www.maxvergelli.com/how-to-parse-and-process-html-xml-in-php/">How to parse and process HTML/XML in PHP</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/how-to-parse-and-process-html-xml-in-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">239</post-id>	</item>
		<item>
		<title>Access a variable declared in a phtml from another phtml in Magento2</title>
		<link>https://www.maxvergelli.com/access-a-variable-declared-in-a-phtml-from-another-phtml-in-magento2/</link>
					<comments>https://www.maxvergelli.com/access-a-variable-declared-in-a-phtml-from-another-phtml-in-magento2/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Tue, 14 Apr 2020 16:25:00 +0000</pubDate>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[blocks]]></category>
		<category><![CDATA[catalog-product-view]]></category>
		<category><![CDATA[custom-block]]></category>
		<category><![CDATA[custom-module]]></category>
		<category><![CDATA[global-variable]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[magento2]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[phtml]]></category>
		<category><![CDATA[product-view]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[template-system]]></category>
		<category><![CDATA[variable]]></category>
		<guid isPermaLink="false">https://www.maxvergelli.com/?p=237</guid>

					<description><![CDATA[<p>Having two blocks in the catalog_product_view.xml file like this: To access a variable declared in the first block from the second block, you can set the variable with register from the first phtml, then you get the value in the &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/access-a-variable-declared-in-a-phtml-from-another-phtml-in-magento2/" aria-label="Access a variable declared in a phtml from another phtml in Magento2">Read More</a></p>
<p>The post <a href="https://www.maxvergelli.com/access-a-variable-declared-in-a-phtml-from-another-phtml-in-magento2/">Access a variable declared in a phtml from another phtml in Magento2</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Having two blocks in the <code>catalog_product_view.xml</code> file like this:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;xml&quot;,&quot;mime&quot;:&quot;application/xml&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;XML&quot;,&quot;modeName&quot;:&quot;xml&quot;}">&lt;block class=&quot;Magento\Catalog\Block\Product\View&quot; name=&quot;product.info.custom-product-attributes&quot; template=&quot;product/view/custom-product-attributes.phtml&quot; after=&quot;product.info.overview&quot;/&gt;
...
&lt;block class=&quot;Magento\Catalog\Block\Product\View&quot; name=&quot;product.info.custom-estimated-delivery&quot; template=&quot;product/view/custom-estimated-delivery.phtml&quot; after=&quot;product.price.final&quot;/&gt;</pre></div>



<p>To access a variable declared in the first block from the second block, you can set the variable with <code>register</code> from the first phtml, then you get the value in the 2nd phtml with <code>registry</code></p>



<p>To do things well without injecting direclty the objectManager in phtml, you have to create some function your product block, so in your block : <code>app/code/Vendor/Modulename/Block/Custom.php</code>assuming that your variable name is : <code>$tech</code> add the following code:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">&lt;?php
namespace Vendor\Modulename\Block;

class Custom extends \Magento\Framework\View\Element\Template
{
    protected $_coreRegistry;

    public function __construct(
        ...
        \Magento\Framework\Registry $coreRegistry
    ) {
        ...
        $this-&gt;_coreRegistry = $coreRegistry;
    }

    /**
     * Set var data
     */
    public function setTechData($data)
    {
        $this-&gt;_coreRegistry-&gt;register('tech', $data);
    }

    /**
     * Get var data
     */
    public function getTechData()
    {
        return $this-&gt;_coreRegistry-&gt;registry('tech');
    }
}</pre></div>



<p>Then in your First phtml :</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">&lt;?php $tech = 'Your Data here'; ?&gt;
&lt;?php $block-&gt;setTechData($tech); ?&gt;</pre></div>



<p>Then, in the Second phtml :</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">&lt;?php $block-&gt;getTechData(); ?&gt; //you'll get your tech value here</pre></div>



<p>Besides, you can also do that in phtml to <strong>test</strong> without the block solution, </p>



<p>First phtml :</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">&lt;?php 
$tech = 'Your Data here';
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$objectManager-&gt;create(&quot;Magento\Framework\Registry&quot;)-&gt;register('tech', $tech);
?&gt;</pre></div>



<p>Second phtml :</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">&lt;?php 
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$techData = $objectManager-&gt;create(&quot;Magento\Framework\Registry&quot;)-&gt;registry('tech');
echo $techData;
?&gt;</pre></div><p>The post <a href="https://www.maxvergelli.com/access-a-variable-declared-in-a-phtml-from-another-phtml-in-magento2/">Access a variable declared in a phtml from another phtml in Magento2</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/access-a-variable-declared-in-a-phtml-from-another-phtml-in-magento2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">237</post-id>	</item>
		<item>
		<title>Single line &#8220;if&#8221; statement in VBScript (like in C# or PHP)</title>
		<link>https://www.maxvergelli.com/single-line-if-statement-in-vbscript-like-in-c-or-php/</link>
					<comments>https://www.maxvergelli.com/single-line-if-statement-in-vbscript-like-in-c-or-php/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Mon, 13 Apr 2020 16:09:00 +0000</pubDate>
				<category><![CDATA[Classic ASP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[asp-classic]]></category>
		<category><![CDATA[aspx]]></category>
		<category><![CDATA[conditional-if]]></category>
		<category><![CDATA[conditional-operator]]></category>
		<category><![CDATA[function-like-c]]></category>
		<category><![CDATA[function-like-php]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[single-if]]></category>
		<category><![CDATA[statement]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[ternary-operator]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[vbscript-syntax]]></category>
		<category><![CDATA[visual-basic-script]]></category>
		<guid isPermaLink="false">https://www.maxvergelli.com/?p=234</guid>

					<description><![CDATA[<p>The &#8220;single line if statement&#8221; exists in C# and VB.NET as in many other programming and script languages in the following format The conditional ternary operator doesn&#8217;t exist out of the box, but it&#8217;s pretty easy to create your own &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/single-line-if-statement-in-vbscript-like-in-c-or-php/" aria-label="Single line &#8220;if&#8221; statement in VBScript (like in C# or PHP)">Read More</a></p>
<p>The post <a href="https://www.maxvergelli.com/single-line-if-statement-in-vbscript-like-in-c-or-php/">Single line “if” statement in VBScript (like in C# or PHP)</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>The &#8220;single line if statement&#8221; exists in C# and VB.NET as in many other programming and script languages in the following format</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">lunchLocation = (dayOfTheWeek == &quot;Tuesday&quot;) ? &quot;Fuddruckers&quot; : &quot;Food Court&quot;;</pre></div>



<p>The conditional ternary operator doesn&#8217;t exist out of the box, but it&#8217;s pretty easy to create your own function in VBScript:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vbscript&quot;,&quot;mime&quot;:&quot;text/vbscript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;VBScript&quot;,&quot;modeName&quot;:&quot;vb&quot;}">Function IIf(bClause, sTrue, sFalse)
    If CBool(bClause) Then
        IIf = sTrue
    Else 
        IIf = sFalse
    End If
End Function</pre></div>



<p>You can then use this, as for the example above:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vbscript&quot;,&quot;mime&quot;:&quot;text/vbscript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;VBScript&quot;,&quot;modeName&quot;:&quot;vb&quot;}">lunchLocation = IIf(dayOfTheWeek = &quot;Tuesday&quot;, &quot;Fuddruckers&quot;, &quot;Food Court&quot;)</pre></div>



<p>The advantage of this over using a single line <code>If</code>/<code>Then</code>/<code>Else</code> is that it can be directly concatenated with other strings. Using <code>If</code>/<code>Then</code>/<code>Else</code> on a single line must be the only statement on that line.</p>



<p>There is no error checking on this, and the function expects a well formed expression that can be evaluated to a boolean passed in as the clause.</p>



<p>It&#8217;s also worth noting that unlike a real ternary operator, <strong>both the <code>sTrue</code> and <code>sFalse</code> parameters will be evaluated regardless of the value of <code>bClause</code></strong>. This is fine if you use it with strings as in the question, but be very careful if you pass in functions as the second and third parameters!</p><p>The post <a href="https://www.maxvergelli.com/single-line-if-statement-in-vbscript-like-in-c-or-php/">Single line “if” statement in VBScript (like in C# or PHP)</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/single-line-if-statement-in-vbscript-like-in-c-or-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">234</post-id>	</item>
		<item>
		<title>Render a Section in a Partial View &#8211; ASP.Net MVC</title>
		<link>https://www.maxvergelli.com/render-a-section-in-a-partial-view-asp-net-mvc/</link>
					<comments>https://www.maxvergelli.com/render-a-section-in-a-partial-view-asp-net-mvc/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Sun, 12 Apr 2020 15:34:00 +0000</pubDate>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[asp.net-mvc]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[mvc-partial-view]]></category>
		<category><![CDATA[mvc-project]]></category>
		<category><![CDATA[mvc-view]]></category>
		<category><![CDATA[partial-view]]></category>
		<category><![CDATA[razor]]></category>
		<category><![CDATA[render]]></category>
		<category><![CDATA[section]]></category>
		<category><![CDATA[vb.net]]></category>
		<guid isPermaLink="false">https://www.maxvergelli.com/?p=231</guid>

					<description><![CDATA[<p>Let&#8217;s start with the following configuration to give an example: in a MVC project, you have a &#8220;_Layout.vbhtml&#8221; file with this code Then, you have a Partial View &#8220;ValidationScripts.vbhtml&#8221; in the Shared folder with If you call the Partial View &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/render-a-section-in-a-partial-view-asp-net-mvc/" aria-label="Render a Section in a Partial View &#8211; ASP.Net MVC">Read More</a></p>
<p>The post <a href="https://www.maxvergelli.com/render-a-section-in-a-partial-view-asp-net-mvc/">Render a Section in a Partial View – ASP.Net MVC</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Let&#8217;s start with the following configuration to give an example: in a MVC project, you have a &#8220;_Layout.vbhtml&#8221; file with this code</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
	&lt;!-- some code here --&gt;
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery-1.8.2.min.js&quot;)&quot;&gt;		&lt;/script&gt;
    @RenderSection(&quot;Scripts&quot;, false)
  &lt;/body&gt;
&lt;/html&gt;</pre></div>



<p>Then, you have a Partial View &#8220;ValidationScripts.vbhtml&#8221; in the Shared folder with</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">@Section Scripts
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.validate.min.js&quot;)&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.validate.unobtrusive.min.js&quot;)&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.validate.fix.js&quot;)&quot;&gt;&lt;/script&gt;  
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/localization/messages_de.js&quot;)&quot;&gt;&lt;/script&gt;      
End Section</pre></div>



<p>If you call the Partial View from a View like this…</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">@ModelType MvcExample.MyModel
@Code
    ViewData(&quot;Title&quot;) = &quot;Test&quot;
End Code

@Html.Partial(&quot;ValidationScripts&quot;)

&lt;h2&gt;Just a Test&lt;/h2&gt;</pre></div>



<p>However the Section &#8220;Scripts&#8221; is not rendered on the page, and the output HTML will be&#8230;</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
    
    &lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery-1.8.2.min.js&quot;)&quot;&gt;&lt;/script&gt;

  &lt;/body&gt;
&lt;/html&gt;</pre></div>



<p><strong>Solution</strong></p>



<p>To render the Section in the Partial View, you need to create a couple of Extension methods like this:</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">public static class HtmlHelperExtensions
{
  private const string _jSViewDataName = &quot;RenderJavaScript&quot;;
  private const string _styleViewDataName = &quot;RenderStyle&quot;;

  public static void AddJavaScript(this HtmlHelper htmlHelper, 
                                   string scriptURL)
  {
    List&lt;string&gt; scriptList = htmlHelper.ViewContext.HttpContext
      .Items[HtmlHelperExtensions._jSViewDataName] as List&lt;string&gt;;
    if (scriptList != null)
    {
      if (!scriptList.Contains(scriptURL))
      {
        scriptList.Add(scriptURL);
      }
    }
    else
    {
      scriptList = new List&lt;string&gt;();
      scriptList.Add(scriptURL);
      htmlHelper.ViewContext.HttpContext
        .Items.Add(HtmlHelperExtensions._jSViewDataName, scriptList);
    }
  }

  public static MvcHtmlString RenderJavaScripts(this HtmlHelper HtmlHelper)
  {
    StringBuilder result = new StringBuilder();

    List&lt;string&gt; scriptList = HtmlHelper.ViewContext.HttpContext
      .Items[HtmlHelperExtensions._jSViewDataName] as List&lt;string&gt;;
    if (scriptList != null)
    {
      foreach (string script in scriptList)
      {
        result.AppendLine(string.Format(
          &quot;&lt;script type=\&quot;text/javascript\&quot; src=\&quot;{0}\&quot;&gt;&lt;/script&gt;&quot;, 
          script));
      }
    }

    return MvcHtmlString.Create(result.ToString());
  }

  public static void AddStyle(this HtmlHelper htmlHelper, string styleURL)
  {
    List&lt;string&gt; styleList = htmlHelper.ViewContext.HttpContext
      .Items[HtmlHelperExtensions._styleViewDataName] as List&lt;string&gt;;

   if (styleList != null)
   {
     if (!styleList.Contains(styleURL))
     {
       styleList.Add(styleURL);
     }
   }
   else
   {
     styleList = new List&lt;string&gt;();
     styleList.Add(styleURL);
     htmlHelper.ViewContext.HttpContext
       .Items.Add(HtmlHelperExtensions._styleViewDataName, styleList);
   }
 }

 public static MvcHtmlString RenderStyles(this HtmlHelper htmlHelper)
 {
   StringBuilder result = new StringBuilder();

   List&lt;string&gt; styleList = htmlHelper.ViewContext.HttpContext
     .Items[HtmlHelperExtensions._styleViewDataName] as List&lt;string&gt;;

   if (styleList != null)
   {
     foreach (string script in styleList)
     {
       result.AppendLine(string.Format(
         &quot;&lt;link href=\&quot;{0}\&quot; rel=\&quot;stylesheet\&quot; type=\&quot;text/css\&quot; /&gt;&quot;, 
         script));
     }
   }

  return MvcHtmlString.Create(result.ToString());
  }
}</pre></div>



<p>So, on any View or Partial View or Display/Edit Template you simply add what you need:</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">@{
  Html.AddJavaScript(&quot;http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js&quot;);
}</pre></div>



<p>Then, in your Layouts you render it where you want it! Like this markup&#8230;</p>



<div class="wp-block-codemirror-blocks-code-block alignfull code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;vb&quot;,&quot;mime&quot;:&quot;text/x-vb&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;full&quot;,&quot;language&quot;:&quot;VB.NET&quot;,&quot;modeName&quot;:&quot;vb&quot;}">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
  @Html.RenderStyles()
  @Html.RenderJavascripts()</pre></div>



<p></p><p>The post <a href="https://www.maxvergelli.com/render-a-section-in-a-partial-view-asp-net-mvc/">Render a Section in a Partial View – ASP.Net MVC</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/render-a-section-in-a-partial-view-asp-net-mvc/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">231</post-id>	</item>
		<item>
		<title>Set “top,left” of an element with the position relative to the parent in jQuery</title>
		<link>https://www.maxvergelli.com/set-topleft-of-an-element-with-the-position-relative-to-the-parent-in-jquery/</link>
					<comments>https://www.maxvergelli.com/set-topleft-of-an-element-with-the-position-relative-to-the-parent-in-jquery/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Sat, 11 Apr 2020 14:00:00 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[coordinates]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css-left]]></category>
		<category><![CDATA[css-top]]></category>
		<category><![CDATA[document]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[element]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery-element]]></category>
		<category><![CDATA[jquery-offset]]></category>
		<category><![CDATA[jquery-position]]></category>
		<category><![CDATA[jquery-positioning]]></category>
		<category><![CDATA[left]]></category>
		<category><![CDATA[offset]]></category>
		<category><![CDATA[parent]]></category>
		<category><![CDATA[position]]></category>
		<category><![CDATA[position-relative]]></category>
		<guid isPermaLink="false">https://www.maxvergelli.com/?p=213</guid>

					<description><![CDATA[<p>The .offset([coordinates]) method set the coordinates of an element but only relative to the document. Then how can we set coordinates of an element but relative to the parent? The.position() method get only &#8220;top,left&#8221; values relative to the parent, but &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/set-topleft-of-an-element-with-the-position-relative-to-the-parent-in-jquery/" aria-label="Set “top,left” of an element with the position relative to the parent in jQuery">Read More</a></p>
<p>The post <a href="https://www.maxvergelli.com/set-topleft-of-an-element-with-the-position-relative-to-the-parent-in-jquery/">Set “top,left” of an element with the position relative to the parent in jQuery</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>The <code>.offset([coordinates])</code> method set the coordinates of an element but only relative to the document. Then <strong>how can we set coordinates of an element but relative to the parent</strong>?</p>



<p>The<code>.position()</code> method get only &#8220;top,left&#8221; values relative to the parent, but it doesn&#8217;t set any values, so the following code doesn&#8217;t work: </p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;JavaScript&quot;,&quot;modeName&quot;:&quot;js&quot;}">$(&quot;#mydiv&quot;).css({top: 200, left: 200});</pre></div>



<p>Instead, to set the position relative to the parent, we need to set the <code>position:relative</code> of parent and <code>position:absolute</code> of the element, like in the following piece of code:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;JavaScript&quot;,&quot;modeName&quot;:&quot;js&quot;}">$(&quot;#mydiv&quot;).parent().css({position: 'relative'});
$(&quot;#mydiv&quot;).css({top: '200px', left: '200px', position:'absolute'});</pre></div>



<p>This works because <code>position: absolute;</code> positions relatively to the closest <strong>positioned</strong> parent (the closest parent with any position property other than the default <code>static</code>).</p>



<p><strong>Just a reminder: set values correctly in jQuery!</strong> </p>



<p>In jQuery if the value passed is a string type, it must be followed by &#8216;px&#8217; (i.e. <span class="has-inline-color has-virtue-primary-color"><em>&#8217;90px&#8217;</em></span>), where if the value is an integer, it will append the px automatically. The width and height properties are more forgiving (either type works). These are the main differences in the jQuery:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;JavaScript&quot;,&quot;modeName&quot;:&quot;js&quot;}">var x = &quot;90&quot;;
var y = &quot;120&quot;
$(selector).css( { left: x, top: y } ); //does NOT work!
$(selector).css( { left: x + &quot;px&quot;, top: y + &quot;px&quot; } ); //does work!

x = 90;
y = 120;
$(selector).css( { left: x, top: y } ); //does work!</pre></div>



<p>Have fun in jQuery!</p><p>The post <a href="https://www.maxvergelli.com/set-topleft-of-an-element-with-the-position-relative-to-the-parent-in-jquery/">Set “top,left” of an element with the position relative to the parent in jQuery</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/set-topleft-of-an-element-with-the-position-relative-to-the-parent-in-jquery/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">213</post-id>	</item>
		<item>
		<title>Display the total number of days between two dates in PHP</title>
		<link>https://www.maxvergelli.com/how-to-display-total-number-of-days-between-two-dates-in-php/</link>
					<comments>https://www.maxvergelli.com/how-to-display-total-number-of-days-between-two-dates-in-php/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Fri, 10 Apr 2020 14:30:00 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[String Manipulation Algorithms]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[count-days]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[date-conversion]]></category>
		<category><![CDATA[date-interval]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[filtering]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[time-difference]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=147</guid>

					<description><![CDATA[<p>PHP: How to display the total number of days between two dates in PHP, using the DateTime class and compare them via diff() method</p>
<p>The post <a href="https://www.maxvergelli.com/how-to-display-total-number-of-days-between-two-dates-in-php/">Display the total number of days between two dates in PHP</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>To count the total number of days between two dates, use the <code>DateTime</code> class and compare them via <code>diff()</code> method with the following few lines of code</p>


<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">$date1 = new DateTime('2020-01-01'); 
$date2 = new DateTime('2020-02-15'); 
print_r($date1-&gt;diff($date2));</pre></div>



<p>And the output will be:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;application/json&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;languageLabel&quot;:&quot;no&quot;,&quot;language&quot;:&quot;JSON&quot;,&quot;modeName&quot;:&quot;json&quot;}">DateInterval Object ( 
  [y] =&gt; 0 
  [m] =&gt; 1 
  [d] =&gt; 14 
  [h] =&gt; 0 
  [i] =&gt; 0 
  [s] =&gt; 0 
  [f] =&gt; 0 
  [weekday] =&gt; 0 
  [weekday_behavior] =&gt; 0 
  [first_last_day_of] =&gt; 0 
  [invert] =&gt; 0 
  [days] =&gt; 45 
  [special_type] =&gt; 0 
  [special_amount] =&gt; 0 
  [have_weekday_relative] =&gt; 0 
  [have_special_relative] =&gt; 0 
)</pre></div><p>The post <a href="https://www.maxvergelli.com/how-to-display-total-number-of-days-between-two-dates-in-php/">Display the total number of days between two dates in PHP</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/how-to-display-total-number-of-days-between-two-dates-in-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">147</post-id>	</item>
		<item>
		<title>Resize an image with the same aspect ratio or with custom and crop sizes in PHP</title>
		<link>https://www.maxvergelli.com/how-to-resize-an-image-with-the-same-aspect-ratio-or-with-custom-and-crop-sizes-in-php/</link>
					<comments>https://www.maxvergelli.com/how-to-resize-an-image-with-the-same-aspect-ratio-or-with-custom-and-crop-sizes-in-php/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Tue, 07 Apr 2020 14:33:47 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[aspect-ratio]]></category>
		<category><![CDATA[crop]]></category>
		<category><![CDATA[custom-dimensions]]></category>
		<category><![CDATA[dimensions]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php-class]]></category>
		<category><![CDATA[php-function]]></category>
		<category><![CDATA[resize]]></category>
		<category><![CDATA[resize-image]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=193</guid>

					<description><![CDATA[<p>In this article, I will explain how to resize an image in two different ways resizing with custom dimensions keeping the same proportions/aspect ratio Method 1: Resizing with custom dimensions The most practical method in PHP to resize an image &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/how-to-resize-an-image-with-the-same-aspect-ratio-or-with-custom-and-crop-sizes-in-php/" aria-label="Resize an image with the same aspect ratio or with custom and crop sizes in PHP">Read More</a></p>
<p>The post <a href="https://www.maxvergelli.com/how-to-resize-an-image-with-the-same-aspect-ratio-or-with-custom-and-crop-sizes-in-php/">Resize an image with the same aspect ratio or with custom and crop sizes in PHP</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>In this article, I will explain how to resize an image in two different ways</p>



<ul><li>resizing with custom dimensions</li><li>keeping the same proportions/aspect ratio</li></ul>



<p><strong>Method 1: Resizing with custom dimensions</strong><br><br>The most practical method in PHP to resize an image with custom and crop sizes (without keeping the original proportions/aspect ratio) is implementing the following function: </p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">function resize_image($file, $w, $h, $crop=false) {
    list($width, $height) = getimagesize($file);
    $r = $width / $height;
    if ($crop) {
        if ($width &gt; $height) {
            $width = ceil($width-($width*abs($r-$w/$h)));
        } else {
            $height = ceil($height-($height*abs($r-$w/$h)));
        }
        $newwidth = $w;
        $newheight = $h;
    } else {
        if ($w/$h &gt; $r) {
            $newwidth = $h*$r;
            $newheight = $h;
        } else {
            $newheight = $w/$r;
            $newwidth = $w;
        }
    }
    $src = imagecreatefromjpeg($file);
    $dst = imagecreatetruecolor($newwidth, $newheight);
    imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

    return $dst;
}</pre></div>



<p>if you set the $crop value on <em>true</em>, the image will be cropped starting from the center, otherwise it will be resized with the new values of width and height</p>



<p><strong>Method 2: keeping the aspect ratio</strong></p>



<p>The second method implements the SimpleImage class by Simon Jarvis, save in a new *.php file the following class and <em>require_once</em> it in your current script</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">/*
* File: SimpleImage.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 08/11/06
* Link: http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
* http://www.gnu.org/licenses/gpl.html
*
*/

class SimpleImage {

   var $image;
   var $image_type;

   function load($filename) {

      $image_info = getimagesize($filename);
      $this-&gt;image_type = $image_info[2];
      if( $this-&gt;image_type == IMAGETYPE_JPEG ) {

         $this-&gt;image = imagecreatefromjpeg($filename);
      } elseif( $this-&gt;image_type == IMAGETYPE_GIF ) {

         $this-&gt;image = imagecreatefromgif($filename);
      } elseif( $this-&gt;image_type == IMAGETYPE_PNG ) {

         $this-&gt;image = imagecreatefrompng($filename);
      }
   }
   function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {

      if( $image_type == IMAGETYPE_JPEG ) {
         imagejpeg($this-&gt;image,$filename,$compression);
      } elseif( $image_type == IMAGETYPE_GIF ) {

         imagegif($this-&gt;image,$filename);
      } elseif( $image_type == IMAGETYPE_PNG ) {

         imagepng($this-&gt;image,$filename);
      }
      if( $permissions != null) {

         chmod($filename,$permissions);
      }
   }
   function output($image_type=IMAGETYPE_JPEG) {

      if( $image_type == IMAGETYPE_JPEG ) {
         imagejpeg($this-&gt;image);
      } elseif( $image_type == IMAGETYPE_GIF ) {

         imagegif($this-&gt;image);
      } elseif( $image_type == IMAGETYPE_PNG ) {

         imagepng($this-&gt;image);
      }
   }
   function getWidth() {

      return imagesx($this-&gt;image);
   }
   function getHeight() {

      return imagesy($this-&gt;image);
   }
   function resizeToHeight($height) {

      $ratio = $height / $this-&gt;getHeight();
      $width = $this-&gt;getWidth() * $ratio;
      $this-&gt;resize($width,$height);
   }

   function resizeToWidth($width) {
      $ratio = $width / $this-&gt;getWidth();
      $height = $this-&gt;getheight() * $ratio;
      $this-&gt;resize($width,$height);
   }

   function scale($scale) {
      $width = $this-&gt;getWidth() * $scale/100;
      $height = $this-&gt;getheight() * $scale/100;
      $this-&gt;resize($width,$height);
   }

   function resize($width,$height) {
      $new_image = imagecreatetruecolor($width, $height);
      imagecopyresampled($new_image, $this-&gt;image, 0, 0, 0, 0, $width, $height, $this-&gt;getWidth(), $this-&gt;getHeight());
      $this-&gt;image = $new_image;
   }      

}
</pre></div>



<p>then you can instantiate the above class in the following way in your script, to resize an image keeping the same proportions:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">$filename = 'your filename here!';		

list($width, $height) = getimagesize($filename);
	
$max_width = 1920;
$max_height = 1080;
$new_width = 1280;
$new_height = 720;

if($width &gt;= $height){
  $ratio = $max_width / $width;
  $new_height = $height * $ratio;
} else {
  $ratio = $max_height / $height;
  $new_width = $width * $ratio;
}

$image = new SimpleImage();
$image-&gt;load($filename);
$image-&gt;resize($new_width, $new_height);
$image-&gt;save($filename);
</pre></div><p>The post <a href="https://www.maxvergelli.com/how-to-resize-an-image-with-the-same-aspect-ratio-or-with-custom-and-crop-sizes-in-php/">Resize an image with the same aspect ratio or with custom and crop sizes in PHP</a> first appeared on <a href="https://www.maxvergelli.com">MaxVergelli.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/how-to-resize-an-image-with-the-same-aspect-ratio-or-with-custom-and-crop-sizes-in-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">193</post-id>	</item>
	</channel>
</rss>
