Important! This is an automatic machine translated page. If you can read english, you should Click Here to read the original English version of the article.

Finding PNG Images Larger Than x Pixels Through the Linux Shell Găsirea PNG imagini mai mari de x pixeli Prin Shell Linux

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. Când încercaţi să lucreze la schimbarea de design de site-ul dvs., va trebui să fie în cauză, cu lăţimea de imagini din conţinutul articolului dumneavoastră. 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. Am capturi de ecran notorie mari, pe de cele mai multe articole le-am scris, aşa că dacă vreau să crească bara laterală este critic pentru a descoperi ce imaginile vor fi prea mare pentru a se potrivi în nou design.

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? Din Sunt un programator, ar fi uşor pentru mine să scrie o cerere mică pentru a face acest lucru, dar mi-a facut incepe sa te gandesti ... de ce nu mă pot face acest lucru în linia de comandă Linux?

The first thing I figured out was that PNG images display the size data when you run the “file” command on them: Primul lucru pe care-am dat seama a fost că imaginile PNG afişa datele de dimensiunea atunci când executaţi fişierul "" comanda pe ele:

$ file image3.png $ File image3.png
image3.png: PNG image data, 613 x 657, 8-bit/color RGBA, non-interlaced image3.png: PNG datele imaginii, 613 x 657, rgba 8-bit/color, non-interlaced

Very useful since 99% of the picture on this site are in PNG format. Foarte utile, deoarece 99% din imaginea de pe acest site sunt în format PNG. So now to throw it in a loop for all the files in my upload directory: Deci, acum, să arunce într-o buclă pentru toate fişierele din directorul meu de încărcare:

$ for f in *.png;do file $f;done $ Pentru f în *. png; a face dosar $ f; făcut

image.png: PNG image data, 631 x 185, 8-bit/color RGBA, non-interlaced image.png: PNG datele imaginii, 631 x 185, rgba 8-bit/color, non-interlaced
image1.png: PNG image data, 631 x 96, 8-bit/color RGBA, non-interlaced image1.png: PNG datele imaginii, 631 x 96, rgba 8-bit/color, non-interlaced
image10.png: PNG image data, 375 x 395, 8-bit/color RGBA, non-interlaced image10.png: PNG datele imaginii, 375 x 395, rgba 8-bit/color, non-interlaced
image11.png: PNG image data, 484 x 241, 8-bit/color RGBA, non-interlaced image11.png: PNG datele imaginii, 484 x 241, rgba 8-bit/color, non-interlaced
—snipped— -Îndepărtate -

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. Acest lucru este mai util, dar mi-ar trebui să trageţi de date în Excel sau o cerere similară, în scopul de a sorta date, aşa că am decis să utilizeze Linux "tăiate" comandă pentru a scoate doar coloana lăţime.

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. Veţi observa-F5 parametrul spune tăiate pentru a ţine coloana a cincea, şi-d \ cu un spaţiu, după ce spune tăiate pentru a utiliza un spaţiu, ca de delimitare. The slash \ character is an escape character to tell the shell to use the space as a character, and not as whitespace. Slash \ personaj este un caracter de salvare pentru a spune coajă de a folosi spaţiul ca un caracter, şi nu ca spaţiu.

$ for f in *.png;do file $f|cut -f5 -d\ ;done $ Pentru f în *. png; a face fişier $ f | cut-F5-d \; făcut

631 631
631 631
375 375
484 484
—snipped— -Îndepărtate -

Not entirely useful output, is it? Cel de ieşire în întregime util, nu? 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. Să împinge faptul că, printr-o declaraţie bash în cazul în care, şi atunci doar arată datele de ieşire ale comenzii fişier atunci când lăţimea este mai mare decât 600 pixeli.

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). Notice "(backtick) mărcile în jurul" fişier $ f | cut ... "secţiune, care indică faptul că în interiorul comenzile" vor fi prelucrate ca o singură ieşire şi hrănite în declaraţia în cazul în care, în cazul în care folosim o-GT (mai mult de ). Also note that you need spaces around either side of the brackets [ ] De asemenea, reţineţi că aveţi nevoie de spaţii în jurul de fiecare parte a paranteze []

for f in *.png;do if [ `file $f | cut -f5 -d\ ` -gt 600 ] ; then file $f;fi;done pentru f în *. png; face în cazul în [ `fisierul $ f | cut-F5-d \`-GT 600], apoi fisierul $ f; FI; făcut

image.png: PNG image data, 631 x 185, 8-bit/color RGBA, non-interlaced image.png: PNG datele imaginii, 631 x 185, rgba 8-bit/color, non-interlaced
image1.png: PNG image data, 631 x 96, 8-bit/color RGBA, non-interlaced image1.png: PNG datele imaginii, 631 x 96, rgba 8-bit/color, non-interlaced
image17.png: PNG image data, 638 x 340, 8-bit/color RGBA, non-interlaced image17.png: PNG datele imaginii, 638 x 340, rgba 8-bit/color, non-interlaced
image18.png: PNG image data, 608 x 448, 8-bit/color RGBA, non-interlaced image18.png: PNG datele imaginii, 608 x 448, rgba 8-bit/color, non-interlaced
—snipped— -Îndepărtate -

Now we have a list of all the files larger than 600 pixels wide. Acum avem o listă a tuturor fişierelor mai mari de 600 pixeli lăţime. 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: Ai putea ajusta "dosar $ f" de la sfârşitul a ecou doar în numele de fişiere în cazul în care ai nevoie pentru a copia sau a le muta în altă parte:

for f in *.png;do if [ `file $f | cut -f5 -d\ ` -gt 600 ] ; then echo $f;fi;done pentru f în *. png; face în cazul în [ `fisierul $ f | cut-F5-d \`-GT 600], apoi echo $ f; FI; făcut

image.png image.png
image1.png image1.png
image17.png image17.png
image18.png image18.png
—snipped— -Îndepărtate -

The Linux shell is incredibly powerful! Învelişul Linux este incredibil de puternic! 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. Această soluţie nu este cu adevărat practic pentru toată lumea, dar este bine să ştiţi cum să lucraţi cu coajă astfel încât să puteţi realiza acest tip de sarcină atunci când aveţi nevoie la spre.

This article was originally written on 12/20/07 Tagged with: Acest articol a fost scris iniţial pe 12.20.07 Etichetate cu: Linux Linux

Daily Email Updates Daily Actualizări de email

You can get our how-to articles in your inbox each day for free. Aveţi posibilitatea să obţineţi modul nostru de-a articole în Inbox în fiecare zi pentru drum liber. Just enter your name and email below: Doar introduceţi numele dvs. şi e-mail de mai jos:


Name: Nume:
Email: E-mail:

Comments (8) Comentarii (8)

  1. Victor Victor

    Damn those commands look complicated, Fir-ar aceste comenzi arata complicate,

    And then people wonder why linux is so unpopular with the *normal* people… Si apoi, oamenii de mirare de ce Linux este atât de nepopular cu * normale * oameni ...

    Just my 2 cents. Just my 2 centi.

    (linux user btw) (BTW user Linux)

  2. The Geek Geek

    Victor, Victor,

    I certainly wouldn't advocate this type of thing for “normal” people =) Eu cu siguranţă nu doreşte să recomande acest tip de lucru pentru "normale" de oameni =)

  3. Phillip C Donald Sr Phillip C Donald Sr

    Thanks I needed that. Multumesc am nevoie de asta. I am trying to learn linux. I sînt trying pentru a afla Linux.

  4. Dennis Dennis

    Any idea how to do this with jpg's? Orice idee cum să faceţi acest lucru cu jpg's?

  5. The Geek Geek

    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. Nu sunt de fapt sigur, dar cred că ai avea de a găsi o utilitate care ar putea verifica dimensiunile unei imagini jpg, şi ai putea substitui pe linie de comandă.

    Alternatively you could probably write a php, python or perl script and interface with the gd library. Alternativ, ne-ar putea scrie, probabil, un PHP, Python sau Perl script-ul şi interfaţa cu biblioteca GD.

  6. Jeff Jeff

    wow… wow ...
    You should put it into the convert command (imagemagick) to scale it if it's bigger Ar trebui pus-o în comanda convert (ImageMagick) la scară este daca este mai mare

  7. Daniel Daniel

    Nice. Drăguţ. This is a perfect example of the power of the Linux shell. Acesta este un exemplu perfect al puterii de coajă Linux. It may look comlicated, but after you get over the learning curve, you can do things that are incredibly powerful. Se poate arata comlicated, dar după ce trece peste curba de învăţare, poţi să faci lucruri care sunt incredibil de puternice.

    Thanks for the example, Multumesc pentru exemplu,

    Daniel Daniel

    daniel1992.wordpress.com daniel1992.wordpress.com

  8. Artem Russakovskii Artem Russakovskii

    ImageMagick's identify should be able to identify any files you have enabled while compiling it. ImageMagick's identifica ar trebui să poată identifica orice fişierele pe care le-au permis întocmirea în timp ce ea. For example, De exemplu,

    identify ceaec3da6ef432af59fbdad2c93c277e.jpg să identifice 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


Our Friends Our Friends
Getting Started Noţiuni de bază


About How-To Geek Despre "Cum să" Geek
What Is That Process? Ce este acest proces?
svchost.exe svchost.exe
jusched.exe winampa.exe
dwm.exe dwm.exe
ctfmon.exe ctfmon.exe
wmpnetwk.exe wmpnetwk.exe
wmpnscfg.exe wmpnscfg.exe
rundll32.exe rundll32.exe
wfcrun32.exe wfcrun32.exe
Ipoint.exe Ipoint.exe
Itype.exe Itype.exe
Wfica32.exe Wfica32.exe
Mobsync.exe Mobsync.exe
conhost.exe conhost.exe
Dpupdchk.exe Dpupdchk.exe Adobe_Updater.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. Copyright © 2006-2009 HowToGeek.com. All Rights Reserved. Toate drepturile rezervate.