typemill / typemill

Typemill is a lightweight, flat-file CMS designed for simple, fast, and flexible website and eBook creation using Markdown.
https://typemill.net
MIT License
427 stars 60 forks source link

Add image files to media library #260

Closed thenktor closed 2 years ago

thenktor commented 2 years ago

Hi,

while importing some pages from Hugo to Typemill I run across this problem: I could not figure out where to store the image files in the Typemill media folder on the file system, so that they are recognized by the media library, too.

It would be nice if this would be possible, then a simple script could be written to import other static file generators' pages to Typemill.

trendschau commented 2 years ago

It wouldn't be a big thing to create some sort of script where you place the images into the folder "original" and then click a button that regenerates all other image versions that do not exist yet. I can think about that for next release.

Right now Typemill stores all images in three versions:

There is one dirty hack you can try:

If there is no "thumb"-folder, then typemill will scan the live folder and generate thumbs from it. It is some kind of old migration logic from prior typemill versions. Let me know if that worked for you.

thenktor commented 2 years ago

Yep, that works. A rescan image folder button would indeed be nice. Doing file operations on file system level is one reason why I prefer flat file CMS 😉

Another thing I've noticed: Some images in the live folder are much larger in size than the images in the original folder:

bash-4.3# ls -lh original/
-rw-r--r-- 1 http http  38K May 31 09:37 em-01.png
-rw-r--r-- 1 http http  96K May 28 08:55 endorama.jpeg
-rw-r--r-- 1 http http  44K Jun  1 11:34 link-erstellen.png
-rw-r--r-- 1 http http  26K Jun  1 13:49 link-erstellt.png
-rw-r--r-- 1 http http 106K May 26 16:51 cloud-2021-01.png
bash-4.3# ls -lh live/
-rw-r--r-- 1 http http 226K May 31 09:37 em-01.png
-rw-r--r-- 1 http http  52K May 28 08:55 endorama.jpeg
-rw-r--r-- 1 http http 239K Jun  1 11:34 link-erstellen.png
-rw-r--r-- 1 http http  33K Jun  1 13:49 link-erstellt.png
-rw-r--r-- 1 http http 343K May 26 16:51 cloud-2021-01.png

Also I wonder why images are resized for "live" anyways?

trendschau commented 2 years ago

Typemill resizes all images for live according to the image sizes that you can add into the settings. Users very often upload large images that should not be used for the website without resizing. On the other hand, it is very good to upload large images and let typemill create the propper sizes because you still have the best quality image then and you can use them for other sizes: developers can generate image sizes in the template on the fly for example, and the ebook-plugin has the option to use the original sizes to get the best result for pdf-books.

I don't know why the live sizes are larger, can you send me one of the original images like "link-erstellen.png" so I can test the behavior here?

thenktor commented 2 years ago

Hi, I've sent an example image as e-mail to you, because it's not a public image.

trendschau commented 2 years ago

Thank you, I tested it and can confirm it. I suppose it is caused by different standard compression/quality settings for png in the GD library that Typemill uses: https://www.php.net/manual/de/function.imagepng.php

BTW: If you do not want to resize original images, then you can simply set the image width (default 820) in the settings to a very high number like 8200 so the resize script is not triggered. Anyway, the resulting image is still a bit bigger (53kb compared to 43kb) because the image is created with the gd libary after upload, but the difference is not so big anymore.

The other solution would be to make quality params for gd editable in the settings and play around with it. Probably not a big deal, but right now it is not top prio because most of the images work fine, and if you change the standard values, than it will probably have an unwanted effect on other images. Next point is that the settings get a bit crowded with a lot of very special interest features, so I have to rethink how to organize them in the ui. But i will keep that in mind for a next release.

trendschau commented 2 years ago

Please also check this ticket: https://github.com/typemill/typemill/issues/203

trendschau commented 2 years ago

Reminder for me:

trendschau commented 2 years ago

Added a checkbox for image uploades in the blox-editor. If checked, the image will not be resized, instead the original image is copied to the live folder.

This does not work for images in the meta-tab,yet, I have to find another solution for meta-tabs.

Pushed to develop and will be published with 1.4.7

trendschau commented 2 years ago

version 1.4.7 just published.

Maybe I will try to add this feature also to image uploads in meta-fields, but it requires some more logic...