PHP Image Dimensions Linux Find File Awk Sed Primer Tutorial
โœ‚๐Ÿƒ๐Ÿพโ€โ™€๏ธ๐Ÿƒ๐Ÿผโ€โ™‚๏ธ
๐Ÿ“–

PHP Image Dimensions Linux Find File Awk Sed Primer Tutorial

PHP Image Dimensions Linux Find File Awk Sed Primer Tutorial

Weโ€™ve written web applications to list image files via their dimension, based on the incredible ImageMagick, when we presented the blog post thread ending with PHP ImageMagick Image Dimensions Sort Tutorial. But ImageMagick, alas, does not come out of the box with an operating system, always. Looking for an image bigger than or equal to a particular dimension yesterday, our online research had us thinking, โ€œWhat about a macOS (or Mac OS X) and Linux โ€œPHP supervises exec supervises find pipes file pipes awk pipes sedโ€ solution (inspired by this useful link, thanks), relying on not much more than having a Unix (ie. Linux) shell?โ€ Sounds good?! And why, pray tell, when macOS has the Finder desktop app? Well, remarkably, here with macOS Mojave, we think weโ€™ve seen better times (ie. than now) showing image dimensions. But even if we have missed something, weโ€™re looking for โ€ฆ

  • a report โ€ฆ ideally โ€ฆ
  • tabularized โ€ฆ ideally โ€ฆ
  • linkable to the images themselves โ€ฆ and user interactive tailorable as far as being able to โ€ฆ
  • define width and height operator and value constraints (eg. width >= 567 and height < 751)

โ€ฆ which is all beyond a GUI like macOSโ€™s Finder desktop app. But it isnโ€™t beyond our โ€œPHP supervises exec supervises find pipes file pipes awk pipes sedโ€ solution called find_images_via_sizeโšซphp that can be downloaded or tried out at this liveโœ‚run link.

Weโ€™ve long admired unixโ€™s (ie. Linuxโ€™s) sed but our admiration grew with todayโ€™s project. It truly is a star of a piece of software functionality. The modesty of โ€œman sedโ€โ€˜s โ€œsed โ€” stream editorโ€ heading belies the power of the combination โ€ฆ

  • โ€œstreamโ€ being any text piped to it โ€ฆ and โ€ฆ
  • โ€œeditorโ€ which covers a lot more than just a โ€ฆ
    1. โ€œsubstitutingโ€ tool โ€ฆ when you consider its โ€œregexโ€ type syntax particularly featuring its โ€œgroup regexโ€ syntax today allowing it to be โ€ฆ
    2. โ€œexpanding and repeating of dataโ€ tool โ€ฆ eg. find occurrence 1, replace with find occurrence (or back-reference) 1, find occurrence 2, replace with find occurrence (or back-reference) 2,


      $ echo " in Spain " | sed 's/\(\ \)\(in\ [^\ ]*\)/The rain\1\2\1falls mainly on the plain./g'

      The rain in Spain falls mainly on the plain.

      $

Add the incredible Linux (and macOS command line) find and file and awk into the mix and behind the scenes of our PHP web application and PHP could have fed exec (after a quiche entree) โ€ฆ for the example of our MAMP document root HTTP://localhost:888/find_images_via_size.php address bar URL โ€ฆ



cd /Applications/MAMP/htdocs; find . -name '*.*g' -exec file {} \; | sed 's/\(.*g\): .* \([0-9]* x [0-9]*\).*/\2 \1/' | awk 'int($1) > 500 && int($3) > 500 {print}' | sed 's/\(\ \)\(\.[^\<]*\)/\ \<a target=_blank title="\/Applications\/MAMP\/htdocs\/\2" href="\2"\>\2\<\/a\>/g'

โ€ฆ resulting in (the first five lines of result set) โ€ฆ



625 x 896 <a target=_blank title="/Applications/MAMP/htdocs/./HTMLCSS/MIDI.js-master/examples/images/tuna.png" href="./HTMLCSS/MIDI.js-master/examples/images/tuna.png">./HTMLCSS/MIDI.js-master/examples/images/tuna.png</a>

2880 x 1800 <a target=_blank title="/Applications/MAMP/htdocs/./HTMLCSS/web_audio.png" href="./HTMLCSS/web_audio.png">./HTMLCSS/web_audio.png</a>

800 x 563 <a target=_blank title="/Applications/MAMP/htdocs/./vmcommerce/administrator/templates/hathor/template_preview.png" href="./vmcommerce/administrator/templates/hathor/template_preview.png">./vmcommerce/administrator/templates/hathor/template_preview.png</a>

800 x 767 <a target=_blank title="/Applications/MAMP/htdocs/./vmcommerce/templates/atomic/template_preview.png" href="./vmcommerce/templates/atomic/template_preview.png">./vmcommerce/templates/atomic/template_preview.png</a>

2880 x 1800 <a target=_blank title="/Applications/MAMP/htdocs/./stopPropagation_preventDefault.png" href="./stopPropagation_preventDefault.png">./stopPropagation_preventDefault.png</a>

โ€ฆ the parts thereof gleaned via a combination of user interactive HTML input textbox values and PHP dirname(__FILE__) and Linux awk space delimiter arguments and Linux find data and Linux file data and Linux sed โ€œxโ€ inclusions and Linux sed edits (within as well, regarding those file and awk โ€œreplace with find occurrenceโ€ usages, but others override).



Previous relevant PHP ImageMagick Image Dimensions Sort Tutorial is shown below.

PHP ImageMagick Image Dimensions Sort Tutorial

PHP ImageMagick Image Dimensions Sort Tutorial

Itโ€™s natural for people to try to introduce order into their world. No matter what you think of the goings on in the world, you can โ€œretireโ€ into that โ€œcushioned worldโ€ of I.T. and create your own order. The most common form of โ€œorderโ€ used, we dare to guess, in the I.T. world is to sort data. Our data we started with yesterdayโ€™s PHP ImageMagick Image Dimensions Primer Tutorial in the form of image URLs and their dimensions (plus some other fields) presented in a table are a case in point where a lot of people would be quick to point out โ€œthat it would be good to sort by widthโ€ and those who would โ€œdo a triple pike with a double somersault to see data sorted by heightโ€.

If you are in charge of the data that forms your data, that is easy to arrange. But if you are the โ€œsecond sourceโ€ you need to work out your own ways to manipulate the data to be able to sort it usefully. We found these manipulations still only had to call on โ€ฆ

  • awk # command line processor repeats column field data
  • sed # command line editor most associated with pipe commands

โ€ฆ with the focus, today, on awkโ€˜s String functionality โ€ฆ

โ€ฆ preparing the ground for the Linux command โ€ฆ

  • sort # sort with its -k -t -n -r switches

โ€ฆ enabling the useful sorting of image URL filespec data presented in a table โ€ฆ order indeed!

You can retry this out for yourself at todayโ€™s liveโœ‚run link with its underlying serverside PHP code you could call image_dimensionsโšซphp and changed in thisway as you wish.


Previous relevant PHP ImageMagick Image Dimensions Primer Tutorial is shown below.

PHP ImageMagick Image Dimensions Primer Tutorial

PHP ImageMagick Image Dimensions Primer Tutorial

We revisit the talents of the brilliant ImageMagickโ€˜s Identify command featuring, last, in Location Services iPad Camera Geolocation Png Metadata Tutorial to start down the road of a web server image information presenter web application.

With ImageMagick command line โ€ฆ



identify [webServerImageFileSpec]

โ€ฆ sums up what we build a web application around, having a PHP shell use its exec method to filter the information through (Linux command line) โ€ฆ

  • awk # command line processor repeats column field data
  • sed # command line editor most associated with pipe commands

โ€ฆ to result in the table contents of our image (specification) table in our web application today.

You can try this out for yourself at todayโ€™s liveโœ‚run link with its underlying serverside PHP code you could call image_dimensionsโšซphp as you wish.


Previous relevant Location Services iPad Camera Geolocation Png Metadata Tutorial is shown below.

Location Services iPad Camera Geolocation Png Metadata Tutorial

Location Services iPad Camera Geolocation Png Metadata Tutorial

Todayโ€™s โ€œfoot further into the waterโ€ progress building on Location Services iPad Camera Geolocation Jpeg Exif Tutorial, as shown below, has a posting title that includes the word โ€œGeolocationโ€, but alas, weโ€™ve found with PNG files coming off our iPad that Geolocation or Geotagging information is lost, unlike our recent iPad JPEG files, and so our preference for the latter has become stronger. We discuss this also at WordPress 4.1.1โ€™s Location Services iPad Camera Geolocation Png Metadata Tutorial. However, there are other interesting pieces of information regarding an image that donโ€™t involve the โ€œwhereโ€ of life, and so we find this topic interesting even so, and hope you do too.

As with so many issues in Information Technology, there are often many approaches to solving problems, and we took the first approach of just some of the possibilities for approaches to PNG metadata processing, listed below โ€ฆ

โ€ฆ and so, once again, we find useful work for the wonderful ImageMagick software product for our purposes. As we say, our foot is just further in the water, and there is more analysis and testing we feel necessary here, but hope this helps you out or is a source of ideas for you.

We leave you with the reworked read_exif_off_image_rotateโšซphp, changed thisway, that has this corresponding new liveโœ‚run.


Previous relevant Location Services iPad Camera Geolocation Jpeg Exif Tutorial is shown below.

Location Services iPad Camera Geolocation Jpeg Exif Tutorial

Location Services iPad Camera Geolocation Jpeg Exif Tutorial

Maybe you were here when we left off with Location Services iPad Camera Geolocation Primer Tutorial as shown below โ€ฆ

  • amazed at the power of mobile devices, specifically an iPad, with their Camera apps and Geolocation data โ€ฆ and/or โ€ฆ
  • not knowing enough โ€ฆ and still not โ€ฆ about when the iPad chooses to output the photograph in *.PNG or *.JPG โ€ฆ ie. the blurb below about meta data versus exif data โ€ฆ and โ€ฆ
  • vowing to be like Fu Manchu โ€ฆ so here we are

Okay, you might want to read more about that iPad decision regarding *.PNG versus *.JPG, and you may want to start here, but in any case, with our fish photographs from that day we got a mix of โ€ฆ

  • JPG
  • PNG

โ€ฆ and as far as teeing into Geolocation (or Geotagging) data goes we, so far, much prefer JPG, because we can use PHP exif methods, and todayโ€™s tutorial is about that, building on what we did at PHP Exif Image Information Rotation Tutorial. As far as the PNG photos go โ€ฆ well, thereโ€™s more to do regarding metadata considerations, and we havenโ€™t given up on that โ€ฆ but that is for another day. In the meantime, enjoy the reworked read_exif_off_image_rotateโšซphp, changed thisway, that has this corresponding new liveโœ‚run link to show that GPS data we havenโ€™t seen up until the fish photographs, and interpreting the exif data now, means we can display a Google Chart Map Chart โ€ฆ

Location Services iPad Camera Geolocation Jpeg Exif Tutorial

โ€ฆ showing the Geolocation context of where and when, and even how high up, this photograph was taken. Cute, huh?!


Previous relevant Location Services iPad Camera Geolocation Primer Tutorial is shown below.

Location Services iPad Camera Geolocation Primer Tutorial

Location Services iPad Camera Geolocation Primer Tutorial

We had occasion to read here about resetting Location Services on an iPad โ€ฆ which, we need to say, youโ€™d only read about and contemplate if something youโ€™ve done has stopped a Geolocation thing you wanted to happen to no longer happen and youโ€™ve ruled out tweaks to Location Service individual app settings with regard to this (and you may have been in on the discussion we had with some time back with Location Services iPad Battery Loss Issue Tutorial) โ€ฆ and the result of doing this opened up the iPadโ€™s Camera app for permission for Location Services to record Geolocation data, and it looks like, time, information on the photographs you take. We also explore this subject at WordPress 4.1.1โ€™s Location Services iPad Camera Geolocation Primer Tutorial. Presumably, this happens in the photographโ€™s exif data, perhaps (am not promising, might pan out to be metadata) โ€ฆ which interests us as well, and weโ€™ll go into that more soon.

So we used this functionality, as well as zooming in on some fish in our pond for todayโ€™s digital photography sojourn. Maybe seeing fish is a source of mindfulness โ€ฆ

Fish

โ€ฆ for you, as it seems to help for me?

The Geolocation aspects are great, as you can imagine, for helping document a trip, in pictures, even well after the event, if you can get the context of where you are when a photograph is taken.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Operating System, Tutorials and tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *