Automatic images gallery

With flickity and php you can realize an automatic images gallery, with automatic titles and (if they are present) metatags:

<div id="gallery" style="width: 50%; margin-left: auto; margin-right: auto; margin-bottom: 4%;">
<div class="carousel" title="cliccare su una immagine per ingrandirla" data-flickity='{ "cellAlign": "center", "contain": true, "fullscreen": true, "wrapAround": true, "lazyLoad": 1 }'>

<?php

$images = glob("your-images-path/*.jpg");
$flag=1;

foreach($images as $image)
{
  // Ricava il titolo dell'immagine (metatag o nome del file)
  $imagedescription = '';
  if (function_exists('exif_read_data')) {
    $exifData = exif_read_data($image);

    // Controlla se esiste un campo di commento o descrizione
    if (isset($exifData['ImageDescription'])) {
      $imagedescription = $exifData['ImageDescription']; // Titolo o descrizione nell'EXIF
    }
  }

  $imageTitle = '';

  // Verifica se la funzione IPTC è disponibile
  if (function_exists('iptcparse')) {
    // Ottieni i metadati IPTC dall'immagine
    $iptcData = iptcparse(@iptcembed('', $image)); // iptcembed recupera i metadati IPTC da un'immagine

    // Controlla se il campo "headline" (titolo) è presente nei metadati IPTC
    if (isset($iptcData[2])) {
      $imageTitle = $iptcData[2][0]; // Il campo 2 è "headline" nell'IPTC
      // Troncamento del titolo se troppo lungo
      $maxLength = 50; // Lunghezza massima del titolo
      if (strlen($imageTitle) > $maxLength) {
        $imageTitle = substr($imageTitle, 0, $maxLength) . '...';
      }
    }
  }

  // Se non c'è un titolo IPTC, usa il nome del file senza trattini
  if (empty($imageTitle)) {
    $imageTitle = pathinfo($image, PATHINFO_FILENAME); // Ottieni il nome del file senza estensione

    // Rimuovi trattini dal nome del file, se presenti
    $imageTitle = str_replace('-', ' ', $imageTitle);
  }


  echo '<div class="carousel-cell' .($flag?' active':''). '">';
  echo '<img title="'. $imagedescription .'" data-flickity-lazyload="'. $image .'" onclick="onClick(this)" />';
  echo "<span class='carusel-image-title'>$imageTitle</span>";
  echo '</div>';
  $flag=0;
}
?>

</div>
</div>

convert pdf to svg

A good website is Convertio: it can convert, for free, your pdf to an svg absolutely identical, from a graphical point of view, with your original pdf, and the text remain text.

But on the other hand the resulting svg file is much bigger than the original pdf, because it is not optimized at all.

Regex replace short paragraph

To replace a paragraph <p> of less than x characters (30 in the example below) with a title (<h3> in the same example), you can use this regex code

search: <p>(.{0,29})</p>
replace: <h3>\1</h3>

chroot in linux

Chroot is a very useful feature in Linux systems: you can update a Linux installation on your PC not within that installation, as usually we can do, but from another installation.

I.g. if you have Linux1 on /dev/sda2 and Linux2 on /dev/sda3 and you cannot login into Linux2, you can try to solve the problem by doing an update of Linux2 from Linux1. Using chroot.

There are very good guides on the web, but, let us repeat the essential steps

  • first of all be sure of the correct name of the partition you want chroot in (i.g. /dev/sda3, or /dev/sdb2)
  • create a /mnt where you will mount that installation, i.g. /mnt/chroot
  • mount that installation in /mnt/chroot: sudo mount -t ext4 /dev/sda3 /mnt/chroot (note that etx4 is if that is the filesystem, but it could be btrfs as well or another filesystem)
  • mount efi partion (if you have efi): sudo mount -t vfat /dev/sda1 /mnt/chroot/boot/efi/
  • mount virtual folders of that installation: for i in dev proc sys run; do sudo mount --bind /$i /mnt/chroot/$i; done
  • Do the chroot: sudo chroot /mnt/chroot

What you do now, within the terminal where you did the chroot is what you could do if you were in that installation (Linux2).
Typically you should do these commands

  • apt update (without sudo before apt: you are already acting as superuser)
  • apt upgrade (or apt full-upgrade)
  • update-grub

Afterwards you can exit with:

  • for i in /dev /proc /sys /run /; do sudo umount -l /mnt/chroot/$i; done
  • and: sudo umount /dev/sda2 /mnt/chroot/boot/efi/
  • and: sudo umount /dev/sda3 /mnt(chroot

Note that these last two commands could be not necessary.

Syncing MS Outlook and Thunderbird

There could be synchronization problems between Thunderbird and the webmail of MS Outlook.

A good, complete guide is here. Because a fault in syncro can be due to the lack of “subscription”, the most important thing is to subscribe all you folders you need to see in TB:

  • right mouse on the account
  • -> subscribe
  • choose what folders subscribe

Like in this screenshot: