PlaceHoldMachine icon indicating copy to clipboard operation
PlaceHoldMachine copied to clipboard

How to skip PNG transparent images?

Open cristianstan opened this issue 8 years ago • 5 comments

Congratulations for this nice project!

I just tested it out. It works smoothly but I have a problem. I need to placehold all images type but excluding the PNG's image format.

Is this possible? If yes how can I achieve this because I wasn't able to find this on the readme section.

Looking forward to your reply,

  • Cristian

cristianstan avatar May 05 '17 06:05 cristianstan

Hi, Cristian! Check for last version of PlaceHoldMachine, it's 1.0.2 now. Method set_allowed_image_formats was added and can be used to solve your issue.

# -*- coding: utf-8 -*- 
from PlaceHoldMachine import PlaceHoldMachine

i = PlaceHoldMachine()
i.log_level = 2

i.allowed_image_formats(['JPEG'])

dirs = [
	'C:/Users/admin/Pictures/test/MediaTrans'
]

i.walk_recursive(dirs)
i.start()

p.s. Don't forget to install latest Pillow with pip install Pillow

Priler avatar May 05 '17 12:05 Priler

That's perfect! Thank you for the fast reply!

Keep up the good work 👍

cristianstan avatar May 05 '17 13:05 cristianstan

I just downloaded the latest version of PlaceHoldMachine.py but when I run the command I get this error:

Traceback (most recent call last):
  File "simple.py", line 8, in <module>
    i.allowed_image_formats(['JPEG'])
TypeError: 'str' object is not callable

In simple.py I added the line (So the error comes from this line): i.allowed_image_formats(['JPEG'])

How can I solve this error? Changing the '*' with 'JPEG' in PlaceHoldMachine.py solves the trick but I'm just curious why it gives me that error?

Any advice?

cristianstan avatar May 05 '17 19:05 cristianstan

Running this code on Python 3.6.0 and Python 2.7.13

# -*- coding: utf-8 -*- 
from PlaceHoldMachine import PlaceHoldMachine #import class

i = PlaceHoldMachine() #create class instance
i.log_level = 2 #set log level to 2, so we can see errors

# set directories list, where all images will be replaced with placeholders
dirs = [
	'C:/Users/admin/Pictures/test/MediaTrans'
]

i.allowed_image_formats(['JPEG'])

i.walk_recursive(dirs) #recursively find all images in given directories
i.start() #begin conversion process

Everything works fine. Can you provide full invalid source code?

Priler avatar May 05 '17 19:05 Priler

Still same problem.

  1. simple.py file contains now the same content provided in your last reply.
# -*- coding: utf-8 -*- 
from PlaceHoldMachine import PlaceHoldMachine #import class

i = PlaceHoldMachine() #create class instance
i.log_level = 2 #set log level to 2, so we can see errors

# set directories list, where all images will be replaced with placeholders
dirs = [
	'C:/Users/CSTAR-PC/Desktop/Dummy_GEN'
]

i.allowed_image_formats(['JPEG'])

i.walk_recursive(dirs) #recursively find all images in given directories
i.start() #begin conversion process

Note: I'm using Python v2.7

cristianstan avatar May 05 '17 20:05 cristianstan