Finding PNG Images Larger Than x Pixels Through the Linux Shell Ieškoti PNG didesnius nei x pikselių Per Linux "Shell"
When you are trying to work on changing the design of your website, you have to be concerned with the width of the pictures in your article content. Kai bandote dirbti keičiasi jūsų svetainės dizainas, turite būti susiję su jūsų straipsnio turinio nuotraukos plotis. I've got notoriously large screenshots on most of the articles I've written, so if I want to increase the sidebar it's critical to figure out which pictures are going to be too wide to fit in the new design. I've got Gerai žinoma, didelis Screenshots daugumą straipsnių aš parašiau, kad jei noriu padidinti Sidebar tai kritinis išsiaiškinti, kurios nuotraukos bus per didelė, kad tilptų naują dizainą.
Since I'ma programmer, it would be easy for me to write a small application to do this, but it made me start thinking… why can't I do this on the Linux command line? Kadangi aš esu programuotojas, tai bus lengva man parašyti prašymą mažas tai daryti, tačiau tai privertė mane apmąstyti ... Kodėl aš negaliu padaryti tai Linux komandinės eilutės?
The first thing I figured out was that PNG images display the size data when you run the “file” command on them: Pirmiausia I figured out buvo, kad PNG vaizdų dydį duomenis, kai paleidžiate "failas" komandą apie juos:
$ file image3.png $ File image3.png
image3.png: PNG image data, 613 x 657, 8-bit/color RGBA, non-interlaced image3.png: PNG duomenimis, 613 x 657, 8-bit/color RGBA, non-interlaced
Very useful since 99% of the picture on this site are in PNG format. Labai naudinga, nes 99% šio tinklalapio vaizdas yra PNG formatu. So now to throw it in a loop for all the files in my upload directory: Taigi dabar mesti jį į visus mano upload katalogo linijos:
$ for f in *.png;do file $f;done $ Dėl F *. png; daryti failas $ f; Priimta
image.png: PNG image data, 631 x 185, 8-bit/color RGBA, non-interlaced image.png: PNG duomenimis, 631 x 185, 8-bit/color RGBA, non-interlaced
image1.png: PNG image data, 631 x 96, 8-bit/color RGBA, non-interlaced image1.png: PNG duomenimis, 631 x 96, 8-bit/color RGBA, non-interlaced
image10.png: PNG image data, 375 x 395, 8-bit/color RGBA, non-interlaced image10.png: PNG duomenimis, 375 x 395, 8-bit/color RGBA, non-interlaced
image11.png: PNG image data, 484 x 241, 8-bit/color RGBA, non-interlaced image11.png: PNG duomenimis, 484 x 241, 8-bit/color RGBA, non-interlaced
—snipped— -Snipped -
This is more useful, but I'd have to pull the data into Excel or a similar application in order to sort the data, so I decided to use the linux “cut” command to pull out just the width column. Tai yra naudinga, tačiau aš jau traukti į Excel ar panaši paraiška duomenų rūšiuoti duomenis, todėl nusprendė naudoti "Linux" Iškirpti "komandą ištraukti tik stulpelio plotį.
You'll notice the -f5 parameter tells cut to take the fifth column, and the -d\ with a space after it tells cut to use a space as the delimiter. Pastebėjus-F5 parametras nurodo sumažinti imtis Penktoje skiltyje, ir-D \ su tarpų po jos liepia sumažinti iki naudojimo erdvės atskirkite. The slash \ character is an escape character to tell the shell to use the space as a character, and not as whitespace. Slash \ pobūdis Escape character pasakyti lukštais naudoti erdvės pobūdį, o ne tarpais.
$ for f in *.png;do file $f|cut -f5 -d\ ;done $ Dėl F *. png; daryti failas $ f | cut-F5-d \; Priimta
631 631
631 631
375 375
484 484
—snipped— -Snipped -
Not entirely useful output, is it? Ne visiškai naudinga galia, tai? Let's push that through a bash if statement, and then only show the output of the file command when the width is larger than 600 pixels. Let's stumti, kad per bash if, ir tik tada rodo failo komandų išėjimo rodmuo, kai plotis yra didesnis nei 600 taškų.
Notice the ` (backtick) marks around the “file $f | cut…” section, which indicate that the commands inside the ` will be processed as a single output and fed into the if statement, where we use a -gt (greater than). Pranešimas "(backtick) ženklai apie" failas $ f | cut ... "dalyje, kurioje nurodoma, kad viduje" bus tvarkomi kaip vieną produkcijos ir įtraukti į ataskaitą, jeigu, kur mes naudojame-GT (daugiau komandų ). Also note that you need spaces around either side of the brackets [ ] Atkreipkite dėmesį, kad jums reikia erdves aplink vieną pusę skliaustuose []
for f in *.png;do if [ `file $f | cut -f5 -d\ ` -gt 600 ] ; then file $f;fi;done for f in *. png; do if [ "failas $ f | cut-F5-d \`-GT 600], tada failą $ f; fi; Priimta
image.png: PNG image data, 631 x 185, 8-bit/color RGBA, non-interlaced image.png: PNG duomenimis, 631 x 185, 8-bit/color RGBA, non-interlaced
image1.png: PNG image data, 631 x 96, 8-bit/color RGBA, non-interlaced image1.png: PNG duomenimis, 631 x 96, 8-bit/color RGBA, non-interlaced
image17.png: PNG image data, 638 x 340, 8-bit/color RGBA, non-interlaced image17.png: PNG duomenimis, 638 x 340, 8-bit/color RGBA, non-interlaced
image18.png: PNG image data, 608 x 448, 8-bit/color RGBA, non-interlaced image18.png: PNG duomenimis, 608 x 448, 8-bit/color RGBA, non-interlaced
—snipped— -Snipped -
Now we have a list of all the files larger than 600 pixels wide. Dabar turime visų failų didesnių nei 600 pikselių pločio. You could adjust the “file $f” at the end to just echo out the filenames if you needed to copy or move them somewhere else: Galima reguliuoti "failas $ f" pabaigoje tiesiog aidas iš varduose, jei jums reikia nukopijuoti arba perkelti juos kur nors kitur:
for f in *.png;do if [ `file $f | cut -f5 -d\ ` -gt 600 ] ; then echo $f;fi;done for f in *. png; do if [ "failas $ f | cut-F5-d \`-GT 600]; tada echo $ f; fi; Priimta
image.png image.png
image1.png image1.png
image17.png image17.png
image18.png image18.png
—snipped— -Snipped -
The Linux shell is incredibly powerful! Linux "Shell neįtikėtinai galinga! This solution isn't really practical for everybody, but it's good to know how to work with the shell so you can accomplish this type of task when you need to. Šis sprendimas yra tikrai naudinga ir visiems, bet gera žinoti, kaip dirbti su lukštais, kad būtų galima atlikti šią užduotį, tipo, kai jums reikia.

Daily Email Updates Dienos paštas Atnaujinimai
You can get our how-to articles in your inbox each day for free. Galite gauti mūsų kaip prie straipsnių į Jūsų pašto dėžutę kasdien nemokamai. Just enter your name and email below: Tiesiog įveskite vardą ir elektroninio pašto adresą žemiau:



Damn those commands look complicated, Damn šių komandų atrodyti sudėtinga,
And then people wonder why linux is so unpopular with the *normal* people… Ir tada žmonės stebisi, kodėl Linux yra toks nepopuliarus * normalus * žmonės ...
Just my 2 cents. Just my 2 cents.
(linux user btw) (Linux vartotojas btw)
Victor, Victor
I certainly wouldn't advocate this type of thing for “normal” people =) Aš tikrai nebūtų advokatė šis dalykas tipo "normalus" žmonės =)
Thanks I needed that. Ačiū, kad man reikia. I am trying to learn linux. Bandau išmokti Linux.
Any idea how to do this with jpg's? Bet idėja, kaip tai padaryti su JPG's?
Dennis, Dennis,
I'm not actually sure, but I think you'd have to find a utility that could check the dimensions of a jpg image, and you could substitute it on the command line. Aš iš tikrųjų tikrai, bet manau, kad jūs turite rasti programa, kuri galėtų patikrinti jpg vaizdus, ir jūs galite jį pakeisti į komandų eilutę.
Alternatively you could probably write a php, python or perl script and interface with the gd library. Arba jūs turbūt galėtų parašyti php, python ar perl scenarijų ir sąsaja su GD biblioteka.
wow… wow ...
You should put it into the convert command (imagemagick) to scale it if it's bigger Jūs turite įdėti į konvertuoti komandą (prog) pagal mastelį, jei ji yra didesnė
Nice. Gražus. This is a perfect example of the power of the Linux shell. Tai puikus pavyzdys, kad reikia Linux shell galia. It may look comlicated, but after you get over the learning curve, you can do things that are incredibly powerful. Ji gali atrodyti comlicated, bet po to, kai gausite per mokymosi kreive, tai galite padaryti dalykus, kurie yra neįtikėtinai stiprus.
Thanks for the example, Ačiū už, pavyzdžiui,
Daniel Daniel
daniel1992.wordpress.com daniel1992.wordpress.com
ImageMagick's identify should be able to identify any files you have enabled while compiling it. ImageMagick yra nustatyti turėtų sugebėti atpažinti visus failus įjungta, o jį skompilowaniem. For example, Pavyzdžiui
identify ceaec3da6ef432af59fbdad2c93c277e.jpg nustatyti ceaec3da6ef432af59fbdad2c93c277e.jpg
ceaec3da6ef432af59fbdad2c93c277e.jpg JPEG 160×90 160×90+0+0 DirectClass 8-bit 10.1797kb ceaec3da6ef432af59fbdad2c93c277e.jpg JPEG 160 × 90 160 × 90 0 0 DirectClass 8-bit 10.1797kb