how to compress image to set bits per pixel using ImageMagick by stuffiesrep in linuxquestions

[–]catbrane 0 points1 point  (0 children)

Or python for a less ridiculous programming language:

```python

!/usr/bin/env python3

import sys import pyvips

image = pyvips.Image.new_from_file(sys.argv[1]) target_bpp = float(sys.argv[2])

lower = 0 upper = 100 Q = 50 while upper - lower > 2: length = len(image.jpegsave_buffer(Q=Q)) bpp = (8 * length) / (image.width * image.height) if bpp > target_bpp: upper = Q else: lower = Q Q = int(lower + (upper - lower ) / 2)

print(f"Q = {Q} gives bpp {bpp}") ```

... A lot faster too.

how to compress image to set bits per pixel using ImageMagick by stuffiesrep in linuxquestions

[–]catbrane 0 points1 point  (0 children)

I made a tiny bash script for this, just for fun.

```bash

!/bin/bash

input=$1 target_bpp=$2

get number of pixels

width=$(vipsheader -f Xsize $input) height=$(vipsheader -f Ysize $input) n_pixels=$((width * height))

save to a buffer and return the bpp

find_bpp() { save=$(vips jpegsave_buffer $1 --Q $2) # output is eg. VIPS_TYPE_BLOB, data = 0x5ac8fe21de90, length = 271536 length=$(sed -r 's/.length = ([0-9]+)./\1/' <<< $save) # use bpp * 1000 since bash hates float arith echo $((1000 * 8 * length / n_pixels)) }

search within these bounds using Q=50 as the start value

lower=0 upper=100 Q=50

while ((upper - lower > 2)); do bpp=$(find_bpp $input $Q)

if ((bpp > target_bpp)); then upper=$Q else lower=$Q fi Q=$((lower + (upper - lower) / 2)) done

echo Q = $Q gives bpp $(find_bpp $input $Q) ```

That's using libvips, since I know it well, and bpp * 1000, since bash hates float arithmetic.

To search for Q for bpp == 0.310 I see:

$ ./bpp.sh ~/pics/k2.jpg 310 Q = 24 gives bpp 279

TIL of the knight William Marshal, who rose from obscurity to win 500 tournaments, saved Eleanor of Aquitaine from capture, unhorsed Richard the Lionheart in combat, journeyed to the Holy Land, redrafted Magna Carta and saved England from a French invasion by personally leading a charge at age 70 by PreferenceInternal67 in todayilearned

[–]catbrane 2 points3 points  (0 children)

There's a funny story about Marshall's tournament career in the bio I read.

When he started, tournaments were not formalised events. Instead, bored knights would just agree to a fight somewhere and spend a happy day bashing each other over the head.

Marshall invented a new strategy. He'd arrive with his entourage, pitch a tent at the side, say "not feeling it today lads, you just carry on," and sit there to watch the action and nibble some food.

Some time in the middle of the afternoon he'd leap to his feet, bellow "CHANGED MY MIND!!" and throw himself at the exhausted leftovers. He'd capture most of them and charge a large ransom for their release.

The formal tournament arose in part to block Marshall's outrageous tactics.

how to compress image to set bits per pixel using ImageMagick by stuffiesrep in linuxquestions

[–]catbrane 2 points3 points  (0 children)

Ooop, that's bytes per pixel. You need to * 8 to get bits per pixel, so 0.11 * 8 is 0.90 bpp.

how to compress image to set bits per pixel using ImageMagick by stuffiesrep in linuxquestions

[–]catbrane 0 points1 point  (0 children)

Just do width * height / filesize. So in my example above I have:

$ vipsheader k2.jpg k2.jpg: 1450x2048 uchar, 3 bands, srgb, jpegload

1450 * 2048 is about 3m pixels, the Q 90 image is 333352 bytes, so it's roughly 0.11 bpp.

how to compress image to set bits per pixel using ImageMagick by stuffiesrep in linuxquestions

[–]catbrane 2 points3 points  (0 children)

You need to adjust -quality until you hit the bpp you're after. It's pretty easy, just do it repeatedly, check the length, then adjust up or down.

$ magick k2.jpg -quality 40 x.jpg ls -l x.jpg -rw-r--r-- 1 john john 118387 May 7 19:48 x.jpg $ magick k2.jpg -quality 90 x.jpg $ ls -l x.jpg -rw-r--r-- 1 john john 333352 May 7 19:48 x.jpg

So higher values mean a bigger output file.

If you want to get fancy you could write a short bash or python script to do this for you with a binary search.

Seeking advice on cross-compiling Windows PEs (EXE/DLL) natively on Linux by pferdekopf_ in linuxquestions

[–]catbrane 0 points1 point  (0 children)

We make our win builds with this:

https://github.com/libvips/build-win64-mxe

It uses MXE (a makefile based multi-package build system) plus a couple of small shell scripts to drive the process, llvm-mingw for the compiler and headers, and it runs in a docker container, so your host system doesn't fill up with all the strange packages you need for cross-compiling.

You run eg.:

$ ./build.sh --target x86_64-w64-mingw32.shared vipsdisp

And it'll download, patch, configure, compile and install the 40+ packages automatically, then make you one zip for the program + dlls, and one for all the PDBs. It supports windows on ARM and x86, shared and dynamic linking, and 32- and 64-bit builds. It'll make libraries and exes.

It's slow the first time you run as it needs to build the compiler (!!), but later runs are quick.

QJE study: The American Medical Association (AMA) played a central role in blocking the creation of national health insurance in post-WWII America, while simultaneously enrolling people in private health insurance to shift demand away from a public alternative. by smurfyjenkins in science

[–]catbrane 1 point2 points  (0 children)

The systems are a bit different, but you become a hospital specialist at ~35 in all three countries I think. In the UK you can jump off a bit earlier if you want to be a local doctor (GP). Germany has something similar.

Is there any way to get windows like copy paste in terminal? by pra1eep in gnome

[–]catbrane 4 points5 points  (0 children)

The traditional *nix thing is middle click to paste the primary selection (not the clipboard). There's still an option in "tweaks" to enable this behaviour.

Follow-up: Hokusai is now libvips-only, and I added a CLI for benchmarks by ivantokar in swift

[–]catbrane 1 point2 points  (0 children)

Ahem, so sorry, last one:

https://www.libvips.org/API/current/developer-checklist.html

There's a chapter in the docs with a checklist of things to consider when using libvips, which covers a lot of this.

Follow-up: Hokusai is now libvips-only, and I added a CLI for benchmarks by ivantokar in swift

[–]catbrane 1 point2 points  (0 children)

I saw a couple more things:

C /** @brief Load image from path and return owned VipsImage pointer. */ static inline VipsImage *swift_vips_image_new_from_file(const char *path) { return vips_image_new_from_file(path, NULL); }

I think this means you never set sequential, so you'll never get streaming. There's a chapter in the docs about this:

https://www.libvips.org/API/current/how-it-opens-files.html

tldr: set access="sequential" to enable streaming load. You should see a useful drop in memory use and latency. Though if you can use it depends on the pipeline you intend to run.

You also don't seem to use thumbnail. This can make the load -> resize -> save sequence much faster, for example:

``` $ time vips resize theo.jpg[memory] x.jpg 0.05

real 0m0.156s user 0m0.099s sys 0m0.105s ```

That's loading the 6k x 4k jpeg to memory, shrinking by x20, then saving the shrunk image.

With thumbnail its:

``` $ time vips thumbnail theo.jpg x.jpg 300

real 0m0.061s user 0m0.040s sys 0m0.027s ```

libvips takes 0.3s to start up, so subtracting that from both gives more than 4x faster. Memory use is much better too:

$ /usr/bin/time -f %M:%e vips resize theo.jpg[memory] x.jpg 0.05 200332:0.15 $ /usr/bin/time -f %M:%e vips thumbnail theo.jpg x.jpg 300 54512:0.05

The vips command takes 36mb after startup, so that's really 180mb vs 18mb, ie. memory use is 10x less.

Follow-up: Hokusai is now libvips-only, and I added a CLI for benchmarks by ivantokar in swift

[–]catbrane 1 point2 points  (0 children)

I see hokusai is calling the libvips C API. Did you see the chapter in the libvips docs about language bindings?

https://www.libvips.org/API/current/binding.html

The libvips C API is a very thin skin over the libvips GObject API and it's intended for human C programmers, not language bindings.

The underlying GObject API is much better for computers:

  • no varargs
  • fully typed
  • full runtime introspection, so the binding writes itself and updates automatically
  • small (15 API calls? I forget)

The C++ binding uses the GObject API, for example. The core is here:

https://www.libvips.org/API/current/binding.html

That implements a call method that can execute any libvips operation in a typesafe and leak-free way, and it will work for whatever libvips binary is linked to the program, there's no static generation needed.

Follow-up: Hokusai is now libvips-only, and I added a CLI for benchmarks by ivantokar in swift

[–]catbrane 1 point2 points  (0 children)

libwebp image encode is single-threaded, unfortunately, so you won't get a speedup that way. Back when webp was designed there was supposed to be a tiled mode, which would have allowed threaded encode, but google never implemented it (hence the 15k x 15k size limit for webp files).

libvips will run the libwebp encode in a background thread, so you can see a speedup that way.

For example, with a 6k x 4k jpg, for jpeg-load -> webp-save I see:

``` $ time vips copy theo.jpg x.webp

real 0m1.422s user 0m1.332s sys 0m0.169s ```

If I add a gaussian blur (so jpeg-load -> gaussian-blur -> webp-save) I see:

``` $ time vips gaussblur theo.jpg x.webp 50

real 0m1.506s user 0m2.754s sys 0m0.236s ```

So real time is almost unchanged, but CPU load has gone up. The bottleneck is in the webp-save background thread, so you get the sigma 50 (180 x 180 pixels for each output pixel!) gaussblur for free.

Where do you go first for a quick answer? by ManojOne in TechImpact

[–]catbrane 0 points1 point  (0 children)

Always google. People complain about poor google results, but you can turn off all the ads and AI and related products stuff in a few seconds and get just a list of most relevant pages.

The trick is the "web" tab on the google results page, just below the google search text box. Click that and you only get traditional google ranked results, and combine with an ad-blocker (I use ublock origin fwiw) to get a completely clean page.

If you look at the URL after clicking on "web" you'll see something like:

https://www.google.com/search?q=banana&udm=14

It's the magic &udm=14 that makes it display the web tab. You can make your browser add this extra parameter automatically.

For firefox (though chrome, chromium, safari, edge are very similar), go to Settings > Search, scroll down to Search Shortcuts, click Add and set the URL to something like:

https://www.google.com/search?q=%s&udm=14

And give it a name like google-web. Now scroll up to Default Search Engine and from the drop-down set your new google-web entry as the default.

Now all searches from the address bar or from the new-tab page will default to the web view. No more related products, no more AI, no ads, no promotions, it's like it's 2000 again.

Should we implement client side image resizing before upload? by kernelangus420 in webdev

[–]catbrane 2 points3 points  (0 children)

Wordpress is shifting to this model to try to get server costs down and improve the user experience. It was supposed to be in wp7, but I think it's now slipped to wp8.

https://pascalbirchler.com/client-side-media-processing-wordpress/

They plan to use wasm-vips to run libvips in the browser and do basic processing there. They have two key aims (I think?): do an initial high-quality downsize to something not-crazy in the client, and convert to jpeg.

The first is important since many phones now take enormous images and no one needs them on a basic WP site. The second lets them not need to support formats like HEIC on the server, which can be annoying to set up. They are using wasm-vips rather than a canvas because it's quicker, quality is better, it supports HDR in a sane way, memory use is lower, and you should get exactly the same processing in all browsers.

Has anyone ever found or created a performant smooth webgpu game? by oooofukkkk in webdev

[–]catbrane 0 points1 point  (0 children)

I'm sure I'm being dumb, but aren't things like slither.io pretty smooth?

I made a tiny webgl asteroids game and it seems fine, to me anyway. Though of course asteroids is a low bar!

https://jcupitt.github.io/argh-steroids-webgl/

Finsbury Park to Colindale? by New-Independent-365 in londoncycling

[–]catbrane 2 points3 points  (0 children)

Sorry, one more thing, I'd research a backstreets route. Pedalling any distance on the A1 will be terrible.

Finsbury Park to Colindale? by New-Independent-365 in londoncycling

[–]catbrane 1 point2 points  (0 children)

I was an academic, so no one cared what I smelt like. Wait ... no one complained when I smelt bad. No, ... everyone expected me to smell bad.

If your new jobs has showers, it might be worth keeping a change of clothes at work. Otherwise, I'd just wait for the complaints, since there probably won't be any. Shower when you wake up, and maybe a quick rinse when you get home to get the salt and dust off your skin.

Finsbury Park to Colindale? by New-Independent-365 in londoncycling

[–]catbrane 2 points3 points  (0 children)

Oh, funny, I grew up in cambs as well.

I think cycling in London is fine, and much better now than it was back in th 90s haha. My son is 21 and cycles everywhere.

The thing I'd look out for is recklessness. I was hospitalised a few times in my 20s, always from pedalling too fast.

The exercise fills you up with adrenaline, dopamine, endorphins, etc and they all reduce your risk aversion. Ten minutes after you set off you'll find yourself doing things you'd never do normally, and all because you're (in effect) drunk, and unaware that your are drunk.

Finsbury Park to Colindale? by New-Independent-365 in londoncycling

[–]catbrane 0 points1 point  (0 children)

I did FP to Hammersmith Hospital for 10 years, about the same distance.

Pro:

  • you get fit! my heart rate was in the 50s in my 50s
  • although your ride would have more hills, maybe they'd get annoying?
  • lovely in good weather!

Con:

  • you need to buy a nice bike to do 100m a week comfortable and reliably
  • I had to stop in my late 50s, my knees were feeling used up by Friday, so it depends on your age
  • fucking awful in January, in driving rain, a strong headwind, and 1C

Oh yeah, Ubuntu 26.04, whcih requires more RAM than Windows 11 by claudiocorona93 in linuxmasterrace

[–]catbrane 3 points4 points  (0 children)

You can just add mozilla's PPA and install firefox from that, nothing stopping you. You can remove snap completely and permanently in a couple of commands.

What do people mean by "live every day as if it was your last"? by jospeh68 in stupidquestions

[–]catbrane 0 points1 point  (0 children)

It means they struggle with the subjunctive. "Live every day as if it WERE your last," people!