AI helps make this site better
AI is the subject of all conversations at the moment, instead of writing an umpteenth article on how it works or whether or not it is revolutionary, I will expose several concrete cases of its use in the creation or operation of this site.
The photos
You have probably noticed that the goal of Universe Photo Archive goes beyond simply archiving a maximum number of photos. It aims to showcase and enhance the most beautiful ones. Two methods are used to achieve this:
- Featuring the photos I find the most stunning on the website’s homepage.
- Writing popular science articles on astronomy and space missions, using the photos as visual aids.
Regarding the first method, I utilize two applications that leverage artificial intelligence.
Improvement of the overall quality of a photograph through AI
Astronomy photos are rarely of perfect quality and sharpness, nor do they always have correct resolution. This is perfectly understandable given the distance between the camera sensor and the subject being photographed, or because the photos were taken a long time ago and/or under quite particular conditions (such as the photos taken on the Moon by astronauts).
In such cases, I use the wonderful open-source software called ‘Upscayl‘ The results I obtain always surprise me. Here are some examples (here you will only see the difference in overall quality, but the resolution can be increased by up to four times).
Credit : NASA
Credits : NASA / SDO / Helioviewer.com
Credit : Hubble (ESA / NASA)
Removal of certain elements
On the homepage of the website, before using Upscayl to enhance the quality of the Apollo mission photos, I make sure to remove any potential dust particles and crosses present on the lens. The application I use to remove elements from a photo is called “Cleanup.pictures” The application removes elements while recalculating what is behind them by extrapolating from the existing content in the image.
For your information, these crosses were primarily used for size and distance measurements.
In the example below, I am also removing other elements just to give you an idea, but this is not typically the case!
Credit : NASA
Programming Language: Adding or Modifying Code with the help of AI
The galleries on this website (the main archive or the wallpaper gallery) use an open-source program called h5ai. This program is highly advanced and provides numerous configuration options. However, it has two shortcomings that I wanted to address:
- The thumbnails are generated in a single folder, which is not ideal for large galleries. If there are tens or hundreds of thousands of thumbnails in a single folder, it can impact the server’s performance where the website is hosted.
- It allows generating and displaying thumbnails for images but not for folders.
Not being extremely comfortable with the PHP language, I sought help from ChatGPT. I will summarize my exchange with this AI for you. Please note that before the exchange you are about to see, I had already made some attempts, but the results were not conclusive. However, this allowed me to significantly improve my request so that ChatGPT can solve my issue on the first try in this exchange.
I will provide you with PHP code in my next message that generates thumbnails for images to be cached (the program is called h5ai). I would like you to modify this code while adhering to several constraints and instructions: _The thumbnails should be generated in a subdirectory of the ‘thumbs’ folder to avoid having all the thumbnails in the same directory.
_Ensure that when the web page is refreshed, the cached thumbnail is displayed, and a new thumbnail is not generated if one already exists in the cache.
_Ensure that even with tens or hundreds of thousands of thumbnails, it remains fast to locate the corresponding thumbnail for the image.
Alright, I’ll wait for you to provide the original PHP code. Once you’ve sent it, I will modify it according to your constraints and instructions.
** In this message, I will spare you the 150 lines of PHP code that I provided to ChatGPT. **
Here are the modifications to be made to the original code:
1: Add theget_subdir
method to theThumb
class to create and return a subdirectory based on the first two characters of the hash:
private function get_subdir($hash) {
$subdir = substr($hash, 0, 2);
$path = $this->thumbs_path . '/' . $subdir;
if (!is_dir($path)) {
@mkdir($path, 0755, true);
}
return $subdir;
}
2: Modify the thumb_href
method to use the subdirectory in the paths and URLs of the thumbnails:
private function thumb_href($source_path, $width, $height) {
if (!file_exists($source_path)) {
return null;
}
$hash = sha1($source_path);
$subdir = $this->get_subdir($hash);
$name = 'thumb-' . $hash . '-' . $width . 'x' . $height . '.jpg';
$thumb_path = $this->thumbs_path . '/' . $subdir . '/' . $name;
$thumb_href = $this->thumbs_href . '/' . $subdir . '/' . $name;
// Le reste de la méthode reste inchangé
}
3: Modify the capture
method to use the subdirectory in the file paths for captures:
private function capture($cmdv, $source_path) {
if (!file_exists($source_path)) {
return null;
}
$hash = sha1($source_path);
$subdir = $this->get_subdir($hash);
$capture_path = $this->thumbs_path . '/' . $subdir . '/capture-' . $hash . '.jpg';
// Le reste de la méthode reste inchangé
}
These modifications will allow storing thumbnails in subdirectories to avoid having all the thumbnails in the same directory and to locate them quickly. The code also checks if a thumbnail already exists in the cache and does not regenerate it if it does.
I will spare you my conversation with ChatGPT regarding the second issue, but it was similar: I wrote a very clear and comprehensive request with all the necessary elements, and I quickly obtained the result that was 100% functional after a few requests for adjustments.
Certainly, it’s not magical, and in this case, a good understanding of programming languages in general and computer science is necessary to guide the request accurately. However, it is indeed a very useful tool.
Download the modifications for the h5ai program.
For those who came across this article solely to address the same issues as mine regarding h5ai, namely adding thumbnails to folders and generating thumbnails in multiple folders, here are some clarifications on these two functionalities and the modified files:
_For folder thumbnails, here’s how it works: simply place a 175×175 pixel image in the folder and name it “folder.jpg” (if you don’t want this file to be visible, you can hide files with this name in the h5ai options). The folder will then use this image as its thumbnail. If no image is detected, the default icon will be displayed.
_For generating thumbnails in multiple folders, as explained by ChatGPT, the code will use the file hash, create a folder with the first two characters of the hash, and generate the thumbnail within that folder. A maximum of 256 folders will be created, and the images will be distributed among them.
IMPORTANT: THESE MODIFICATIONS WERE MADE ON VERSION 0.30.0 of H5AI.
Thumbnails for folders
Replace the script.js
file located at the following location: /_h5ai/public/js/
with the file of the same name provided below.
Thumbnails generation for multiple folders
Replace the class-thumb.php
file located at the following location: /_h5ai/private/php/ext/
with the file of the same name provided below. (Remember to rename the file class-thumb.php.txt to class-thumb.php)
Comments are closed.